Alternative to Exit label
BlitzMax Forums/BlitzMax Programming/Alternative to Exit label
| ||
I don't like it when you exited to a label, it is hard to tell if you exited or not. (the loop might have finished on its own)Print "Hello" 'find target Area For y=1 To 20 For x=1 To 10 If grid_good(x,y) Then ExitArea Next Next 'spot not found? RuntimeError "good place not found. oh no." EndArea 'move Print "moving to good target." This is similar to putting your code in a function, exept that you dont have to pass every local to it. And you dont have to name your loop... We can do this right now: Strict 'find target Local y #label10 For y=1 To 20 For Local x=1 To 10 If grid_good(x,y) Then Exit label10 Next Next 'did we exit? If x=11 And y=21 Then 'error 'x' not found because it shouldnt get accessed here. RuntimeError "good place not found. oh no." Else 'move Print "moving to good target" EndIf The problem with ExitArea is that you couldn't exit out of 2 nested areas. that would be messy anyways. You can do it with exit label. |