Why does my Loop end after 11 Loops? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/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? - Dimster - 02-08-2023 So ... Holey Smoke ... some very informative stuff here. I'm going to print this off and keep it in my Basic Learning How To book. On the issue of Recursion and a Counter, Tempodi remarks Quote:DataCount = DataCount + 7 ' this is another alone variable that does not pass to the next recursive calling But Steve's code, in his Recur subroutine, appears to have a successful counter working. Is there a reset back to zero for all Recursive calls as a normal use of Recursion or this reset to zero happening just in Tempodi's structure of his Recursion subroutine? I seem be getting my counters resetting only when I exit my Recursive routine but working ok within the Recursive calls but, while messing with a redesign of my Recursion call routine, I was able to jump from 11 loops to the 4000 loops, I then did a little more tinkering and now have endless looping going on. I never thought to look at an issue with the counter. RE: Why does my Loop end after 11 Loops? - Kernelpanic - 02-08-2023 Quote:@Dimster - Is there a reset back to zero for all Recursive calls as a normal use of Recursion . . . Not that I know. The classic example of a recursion is the determination of the Fibonacci number. As to the result: In Wikipedia (German), the zero is not taken into account. On the other hand, I orientated myself on the Matheduden. Code: (Select All) $Console:Only RE: Why does my Loop end after 11 Loops? - TempodiBasic - 02-09-2023 @Dimster Quote:But Steve's code, in his Recur subroutine, appears to have a successful counter working. Yes because he uses a SHARED variable declared into the main... in other words he uses one of the way to build a controlled recursive calling. at 38# you can see Code: (Select All) DIM SHARED AS LONG DataCount and in recursive SUB Code: (Select All) IF DataCount = 0 THEN SEEK #1, 1 'move to the start of the file 'may need to change to 0 for 0 index counting I hope to be clear and understandable RE: Why does my Loop end after 11 Loops? - Dimster - 02-09-2023 Ah.. so in a Do Loop the counter doesn't need to be Dimensioned or Shared but in a Recursive call it does. RE: Why does my Loop end after 11 Loops? - mdijkens - 02-10-2023 I still think this is not something to solve with recursion; find another example to play with if you want to experiment with recursion. This scenario could be solved with a static sub that only reads the first time to an array in memory (7*4000 strings is not that much) and subsequent call to the function just reads from the array... my 2ct RE: Why does my Loop end after 11 Loops? - Kernelpanic - 02-10-2023 (02-09-2023, 05:28 PM)Dimster Wrote: Ah.. so in a Do Loop the counter doesn't need to be Dimensioned or Shared but in a Recursive call it does. You don't need a counter. A recursive function calls itself until: n - n = 0. Applies: 0! = 1. This ends the recursive call, and the value is popped off the stack and displayed. (That's how I understand it.) Recursive calculation using the factorial as an example. Code: (Select All) 'Fakultaet rekursiv - 10. Feb. 2023 RE: Why does my Loop end after 11 Loops? - Dimster - 02-10-2023 Thanks for this great advice - and calling a spade a spade in terms of the degree of frustration one should put up with before scraping it all and starting again. The limits and nuisances of Recursion is what I'm playing with. With the help you guys have provided here, my program no longer stops after 11 loops. I'm messing with stacking Recursion - computer is humming. Thanks again RE: Why does my Loop end after 11 Loops? - Kernelpanic - 02-10-2023 (02-10-2023, 07:32 PM)Dimster Wrote: With the help you guys have provided here, my program no longer stops after 11 loops. I'm messing with stacking Recursion - computer is humming. Thanks again The IF . . . ELSE condition is mandatory, otherwise the program goes into an endless loop! Example: 4! (n) If n = 1 -> No --> Else next If n = 1 -> No --> Else and so on ... At last: If n = 1 Yes -> Finish Now the values will be pop from the stack and output. RE: Why does my Loop end after 11 Loops? - Dimster - 02-11-2023 I'm not sure exactly what you mean KernelPanic. I'm not using an IF ...ELSE to end the Recursion but using a counter to Exit Sub. This seems to be working. It's a method I learnt from bPlus and his Recursion by Subroutine. Are you able to clarify what you mean by "mandatory". Will I have a stack issue just using a counter to Exit the Recursion Sub? RE: Why does my Loop end after 11 Loops? - Kernelpanic - 02-11-2023 I don't know how things are going for you now. Is this really a recursive processing, or is something just called after a counter? From Herbert Schildt, C command library, recursion page 102: When developing recursive functions, there have to be an IF statement somewhere that makes the function return without executing another recursive call. Without this provision, the function never returns after it is called. Writing recursive functions without an IF is a common mistake. The same program as above, only without the IF. You have to break it off with Strng-C. Code: (Select All) $Console:Only |