Page 1 of 1

Local declaration, For loop and recursion

Posted: Thu Apr 13, 2023 2:11 pm
by Flinx
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?

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()

Re: Local declaration, For loop and recursion

Posted: Thu Apr 13, 2023 3:45 pm
by airsoftsoftwair
Yes, this is a bug. Will be fixed.

Re: Local declaration, For loop and recursion

Posted: Mon Jul 22, 2024 8:57 pm
by airsoftsoftwair

Code: Select all

- Fix: Recursion was broken with "For" when using a global iterator variable