@bplus fine as you have make a pendulum (infinite palindrome generator) of digit sequence!
It is very interesting and fine! The power of 2 is very strong!
--------
@bplus @Dimster what do you think about the FOR STEP NEXT glitch pointed out by my example?
StartIndex = 2: stepperIndex = 2: DoneIndex = 20
Print "StepperIndex is 2 but when index will be 18 it becomes -2" Print " so we expect to see index to decrement after 18 towards negative digits" For index
= StartIndex
To DoneIndex
Step stepperIndex
Print index;
"->"; index
^ 2;
If index
= 18 Then stepperIndex
= -2 '<------------------------newline
Print "another try: the variable a grows up to 100 step 10 until" Print " it becomes 50, after this variable a should decrease step -10" a = 1: b = 100: c = 10
@Dimster yes you are very near to original sight of my communication
Loop and recursion can be very similar but often a change made into a loop make a very different effect if it is made in a recursion loop.
This is more true when the recursive loop call itself in the middle of sub/function recursive because the rest part of recursive has not been already executed. So you cannot have a more specific control on this part of recursion in the meaning that you cannot know what recursion bring back as true as you cannot know how times the recursion will be called on fly.
From this comes out that you say in your affimation: if you stop a recursion the data in all the sub called are still available, while in the loop you can access only to the data of the current cycle of loop.
But yes recursion is fine, beautyful, elegant and more exciting versus loop when it is possible, you must only pay more attention for details.
see this financial example
$Debug
'recursion versus loop
' calcularion of compound interest of a capital in years of investment
' here a definition: https://en.wikipedia.org/wiki/Future_value#Compound_interest
choice$ = ""
Print " calculation of compound interest of a capital" Print " please type amount of money, annual rate (rate for year), years of investment>" Input "", money!
, AnnRate!
, Years%
Print CompoundInterest_loop
Print compoundInterest_Recursive
(money!
, AnnRate!
, Years%
) Print " press Spacebar to end, another key to replay"
Shared money!
, AnnRate!
, Years%
newmoney! = money! ' we use a local variable to not modify main variable MONEY!
newmoney! = newmoney! + (newmoney! * AnnRate! / 100)
CompoundInterest_loop = newmoney!
Function compoundInterest_Recursive
(newmoney!
, Rate!
, ActYears%
) compoundInterest_Recursive = newmoney! ' <------------- this save last result
Themoney! = newmoney! + ((newmoney! * Rate!) / 100)
ActYears% = ActYears% - 1
money! = compoundInterest_Recursive(Themoney!, Rate!, ActYears%)
compoundInterest_Recursive = money!
-----------------------------------------------
@FellippeHeitor and @QB64 Developers Team
nice to do some sessions of debug.
I find this new feature very powerful.
Waiting when I can observe array variable with variable index.
Thanks for your efforts.