Why does my Loop end after 11 Loops? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Why does my Loop end after 11 Loops? (/showthread.php?tid=1448) |
RE: Why does my Loop end after 11 Loops? - SMcNeill - 02-07-2023 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. RE: Why does my Loop end after 11 Loops? - Dimster - 02-07-2023 It's was just pseudocode. The actual working Recursion with Do Loop does have "Loop" before the recursion call. And thanks Steve for the SEEK stuff on the other thread, definitely right up my alley. I'm still not sure why a bare recursion with a reset of the pointer using Seek only came up with 11 loops, whereas a Recursion of a Do Loop with that same Seek did all the looping required. So, I'm assuming Steve's comment about Seek working with Input may also need the qualifier Seek/Do/Input work together. A Seek/Recursion may have issues but that brings to mind the old adage of the blind man feeling the leg of an elephant and deducing it's a tree, so right can I really be that Seek/Recursion are not compatible? RE: Why does my Loop end after 11 Loops? - bplus - 02-07-2023 (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. Here's my check: I haven't a clue where Dimster can put a loop without messing up recursion RE: Why does my Loop end after 11 Loops? - bplus - 02-07-2023 Here ye go! Code: (Select All) Open "The file" For Input As #1 RE: Why does my Loop end after 11 Loops? - TempodiBasic - 02-07-2023 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 Code: (Select All) Open File 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! RE: Why does my Loop end after 11 Loops? - SMcNeill - 02-07-2023 (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. Like this: Code: (Select All) OPEN "data.txt" FOR INPUT AS #1 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) RE: Why does my Loop end after 11 Loops? - bplus - 02-07-2023 It woiks! save as "The file" Code: (Select All) Now Code: (Select All) Open "The file" For Input As #1 Interesting note: No Static nor Shared needed! And no dang Do... Loop RE: Why does my Loop end after 11 Loops? - SMcNeill - 02-07-2023 @bplus I think you're missing the whole point here -- the objective is to read the file *without* having to OPEN it at the start, or CLOSE it at the end. That's why there's the SEEK in there at the top, to move to INPUT pointer manually to the beginning of the file. It's probably opened once at the start of the program, but read from in various different subroutines and functions. Try my simple post before yours, with your data file. RE: Why does my Loop end after 11 Loops? - bplus - 02-07-2023 The point in my eye is to use recursion to go through and process the file without a main loop. I am sure "The file" would work in your simplest demo that does not use recursion. Seek in my opinion is big fat Red Herring, distraction. RE: Why does my Loop end after 11 Loops? - SMcNeill - 02-07-2023 (02-07-2023, 09:36 PM)bplus Wrote: The point in my eye is to use recursion to go through and process the file without a main loop. Code: (Select All) DIM SHARED AS LONG DataCount, DataItem(7) No main loop? Check. Recursion? Check. SEEK? Check. What's missing here?? |