02-07-2023, 08:59 PM
Hi guys and gals
...
the thread is interesting but also just a little unclear...
Dimster posted his ideas as pseudocode....
the main part of answers posted here talks in BASIC code...
Dimster question was about "why turning my loop into a recursive code I don't get the same result?"
A SUB callilng itsself until a flag doesn't get a specific condition is quiet different from looping with DO/LOOP.
A SUB is just a closed block of code... so you must assure that variables or values needed for ending the job pass from the SUB calling and the SUB called.
looking closest to this pseudocode
1. the SUB Recur has no parameters
2. the variables used as flags are NOT global --> at first run Recur has LoopRecur = 0 and then it becomes 1, and so the same at second run because LoopRecur is local and not GLOBAL (shared) and not passed as parameter
3. I don't understand the Seek #1,1 (coming back at the first byte of the file) but maybe it needs to do the job
4. I imagine that in pseudocode the FOR NEXT loop uses a INPUT #1, DataItem(i), in other words it reads from the file
5. (Mutatis mutandis) at first run of the sub DataCount is 0 and it becomes 1, but so at second run and so on because it is local and not global
6. the IF statement would be infinite because DataCount will not become 4000 ....
7. in the pseudocode with DO/LOOP it uses EOF in reading the file, in that pseudocode with Recur sub this control disappears.
If I have some time I'll write the code to emulate the pseudocode of Dimster without gaining the thousands of lines!
...
the thread is interesting but also just a little unclear...
Dimster posted his ideas as pseudocode....
the main part of answers posted here talks in BASIC code...
Dimster question was about "why turning my loop into a recursive code I don't get the same result?"
A SUB callilng itsself until a flag doesn't get a specific condition is quiet different from looping with DO/LOOP.
A SUB is just a closed block of code... so you must assure that variables or values needed for ending the job pass from the SUB calling and the SUB called.
looking closest to this pseudocode
Code: (Select All)
Open File
Recur
Sub Recur
LoopRecur = LoopRecur + 1
Seek #1, 1
for i = 1 to 7:Input DataItem(i):Next
DataCount = DataCount + 7
Call Subroutine to work on these 7 data items
if DataCount < 4000 then Recur
End Sub
1. the SUB Recur has no parameters
2. the variables used as flags are NOT global --> at first run Recur has LoopRecur = 0 and then it becomes 1, and so the same at second run because LoopRecur is local and not GLOBAL (shared) and not passed as parameter
3. I don't understand the Seek #1,1 (coming back at the first byte of the file) but maybe it needs to do the job
4. I imagine that in pseudocode the FOR NEXT loop uses a INPUT #1, DataItem(i), in other words it reads from the file
5. (Mutatis mutandis) at first run of the sub DataCount is 0 and it becomes 1, but so at second run and so on because it is local and not global
6. the IF statement would be infinite because DataCount will not become 4000 ....
7. in the pseudocode with DO/LOOP it uses EOF in reading the file, in that pseudocode with Recur sub this control disappears.
If I have some time I'll write the code to emulate the pseudocode of Dimster without gaining the thousands of lines!