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



Users browsing this thread: 5 Guest(s)