Local declaration, For loop and recursion

Discuss any general programming issues here
Post Reply
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Local declaration, For loop and recursion

Post 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()
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Local declaration, For loop and recursion

Post by airsoftsoftwair »

Yes, this is a bug. Will be fixed.
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Local declaration, For loop and recursion

Post by airsoftsoftwair »

Code: Select all

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