Global NewList foo()
For i = 1 To 10
AddElement(foo()) : foo() = i
Next i
Procedure FindFoo(int)
ForEach foo()
If foo() = int
ProcedureReturn @foo()
EndIf
Next
EndProcedure
ForEach foo()
Debug foo()
FindFoo(5)
Next
Infinite loop.
I'm wondering if you guys had some safety net to avoid that. I'm tempted to Push/PopListPosition() every time after ForEach and before Next, with a custom macro... or just be careful (but infinite loops can be tricky to debug)
Procedure FindFoo(int)
Protected result
PushListPosition(foo())
ForEach foo()
If foo() = int
; ProcedureReturn @foo()
result = @foo()
break
EndIf
Next
PopListPosition(foo())
ProcedureReturn result
EndProcedure
; A simple duplicate elimination using a nested iteration
;
ForEach Numbers()
Value = Numbers()
PushListPosition(Numbers())
While NextElement(Numbers())
If Numbers() = Value
DeleteElement(Numbers())
EndIf
Wend
PopListPosition(Numbers())
Next
Ups: Too late....
Just because it worked doesn't mean it works. PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Global *No5
ForEach foo()
Debug foo()
*No5 = FindFoo(5)
Next
Debug ""
Debug foo()
Debug PeekI(*No5)
ChangeCurrentElement(foo(), *No5)
Debug foo()
Just because it worked doesn't mean it works. PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).