[22 Sep 2008] Possible bug in For...Next loop
Posted: Sat Jun 13, 2020 5:31 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 22 Sep 2008 15:37:46 -0000
Hello Andreas, I think I've found a bug in For...Next loop using recursive functions, the following piece of code render an object and check if exists object's childs, if so renders them calling recursively the RenderObject() function:
The above function does not work, because when returning from a recursive call the For...Next exit even if <cnt> has not reached the value stored in the variable <childs>.
Instead, using a While...Wend loop, works correctly:
Maybe I'm missing something?
Regards, Fabio
Hello Andreas, I think I've found a bug in For...Next loop using recursive functions, the following piece of code render an object and check if exists object's childs, if so renders them calling recursively the RenderObject() function:
Code: Select all
Function scui.RenderObject(id)
...
; RENDER ALL CHILDS -----------------------------------------------
If helpers.FieldIsNil(Obj, "childlist") = 0
Local cnt
Local childs = helpers.CountEntries(Obj.ChildList)
DebugPrint("RENDERING CHILDS OF ", Obj.oName)
For cnt = 1 To childs
DebugPrint("- Child ", scui.IFO[Obj.ChildList[cnt].Id].oName)
scui.RenderObject(Obj.ChildList[cnt].Id)
Next
EndIf
...
EndFunction
Instead, using a While...Wend loop, works correctly:
Code: Select all
Function scui.RenderObject(id)
...
; RENDER ALL CHILDS -----------------------------------------------
If helpers.FieldIsNil(Obj, "childlist") = 0
Local cnt = 1
Local childs = helpers.CountEntries(Obj.ChildList)
DebugPrint("RENDERING CHILDS OF ", Obj.oName)
While cnt <= childs
;For cnt = 1 To childs
DebugPrint("- Child ", scui.IFO[Obj.ChildList[cnt].Id].oName)
scui.RenderObject(Obj.ChildList[cnt].Id)
cnt = cnt + 1
;Next
Wend
EndIf
...
EndFunction
Regards, Fabio