Local declaration, For loop and recursion
Posted: Thu Apr 13, 2023 2:11 pm
Because a recursive function did not behave as I had hoped, I made an example. The not working For line is commented out.
This For loop is not executed further after returning from the recursion, if the "Local n" is not directly in the loop header. Is this a bug?
This For loop is not executed further after returning from the recursion, if the "Local n" is not directly in the loop header. Is this a bug?
Code: Select all
Function p_test()
rcl=rcl+1
DebugPrint("recursion level",rcl)
Local n
; For n=1 To 2 ; this does not work as expected
For Local n=1 To 2
If rcl=3 Then finish=True ; break at 2 recursions
If Not finish
p_test()
DebugPrint("back at level",rcl,"and n",n)
EndIf
DebugPrint(" n ",n)
Next
rcl=rcl-1
EndFunction
finish=False
p_test()