Why does my Loop end after 11 Loops?
#26
(02-07-2023, 08:49 PM)bplus Wrote:
(02-07-2023, 08:14 PM)SMcNeill Wrote: I'm certain the "recur" at the end of that code is where the LOOP goes.  Dimster didn't post BASIC; just pseudocode for his process -- or else it'd error out on the Open the file segment.  Wink

Here's my check:


I haven't a clue where Dimster can put a loop without messing up recursion  Huh

Like this:
Code: (Select All)
OPEN "data.txt" FOR INPUT AS #1
DIM SHARED DataCount AS LONG
Recur
CLOSE

SUB Recur
    SEEK #1, 1
    DO WHILE NOT EOF(1)
        FOR i = 1 TO 7
            INPUT #1, item(i)
            DataCount = DataCoount + 1
        NEXT
        DO7
        IF DataCount = 4000 THEN EXIT SUB
    LOOP
END SUB

SUB DO7
END SUB

There's no recursion needed here; just a SEEK at the start to make certain that he starts reading from the beginning of the file.

To do it with recursion, the process would be like I posted back on the first page:
Code: (Select All)
DIM SHARED AS LONG DataCount, DataItem(7)
OPEN "someFile.txt" FOR INPUT AS #1
DataCount = 1
Recur

SUB Recur
    IF DataCount = 1 THEN SEEK #1, 1 'move to the start of the file 'may need to change to 0 for 0 index counting
    FOR i = 1 TO 7
        INPUT DataItem(i)
    NEXT
    DataCount = DataCount + 7
    CALL WorkSub
    IF DataCount < 4000 THEN Recur
END SUB

SUB WorkSub
    'work on these specific data items
END SUB
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 SMcNeill - 02-07-2023, 09:02 PM



Users browsing this thread: 18 Guest(s)