Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does my Loop end after 11 Loops?
#35
@Dimster
going on with your pseudocode
I followed the instruction of Bplus to create a text file with the data posted by Bplus for the "The File" that I saved as "The File.txt".
so I took your pseudocode and I translated it to QB64
look at this
Code: (Select All)
Open "The file.txt" For Input As #1 'Open File
Recur
Close #1
End

Sub Recur
    Dim DataItem(1 To 7) As String  ' we define a variable to read text from file
    LoopRecur = LoopRecur + 1  ' this is a alone variable that does not pass to the next recursive calling
    Seek #1, 1  ' this force to read file from the first byte... so we read always the same 7 string data
    For i = 1 To 7: Input #1, DataItem(i): Next
    DataCount = DataCount + 7 ' this is another alone variable that does not pass to the next recursive calling
    WorkDataItem DataItem() 'Call Subroutine to work on these 7 data items
    If DataCount < 14 Then Recur ' this condition it will never happen because DataCount at each run is always 0 and becomes 7
End Sub

Sub WorkDataItem (s() As String)
    For i = 1 To 7 Step 1
        Color i, i-1
        Print s(i); " ";
    Next i
    Color 7 ' restore the default color foreground for text
    Print ' we go ahead
    _Delay .3  'we need this to avoid the crash of program
End Sub
if you run this code, you get an infinite loop that reads only the first 7 data from the file, because SEEK #1,1 resets the file pointer to the first byte of the same file.

and if we want to let working this code we can:

use DataCount as SHARED variable
or
use DataCount as parameter of SUB Recur
or
use DataCount as STATIC variable of SUB Recur
or
use SUB Recur STATIC
....
at yours the choice

in this case you'll get twice the first 7 data from the file. 
If you want to get also the second set of 7 data from the file, you need REMming SEEK #1,1.
Reply


Messages In This Thread
Why does my Loop end after 11 Loops? - by Dimster - 02-06-2023, 07:08 PM
RE: Why does my Loop end after 11 Loops? - by TempodiBasic - 02-08-2023, 12:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exiting sub while inside a loop PhilOfPerth 5 525 12-05-2025, 09:40 AM
Last Post: PhilOfPerth
  Do Loop, Sleep and Mouse Button Dimster 5 599 09-06-2025, 12:57 PM
Last Post: Dimster
  Using modulo to loop through lists fistfullofnails 3 724 09-03-2025, 11:50 PM
Last Post: fistfullofnails
  What is wrong with this for/next loop Helium5793 6 1,152 04-15-2025, 05:11 PM
Last Post: Kernelpanic
  Question on ln in a for/next loop Dimster 13 2,251 09-13-2024, 11:07 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)