'Exit <num>' hack?

BlitzMax Forums/BlitzMax Programming/'Exit <num>' hack?

Russell(Posted 2005) [#1]
A little while ago, someone was asking for a more powerful Exit command that would allow you to jump out of multiple levels of For\Next loops. I haven't tested this, but I would this work?:
#iterate
For a = 0 To 10
  For b = 10 To 0 Step -1
    If b = 5 And a = 5
	a = 10; b = 0  ' Cause loop to end at next reading
	Print "both = 5"
    Else
	Print "a = " + a + " b = " + b
	Print "normal loop"
    EndIf
  Next
Next

Depending on your program, you may need to put a label before the Next that you can jump to so no further code is executed. This is a huge klug and I'm not really sure if it's a good idea, but at least the stack is in the proper state when it exits...

Could someone tweak this?

An 'Exit <levels>' would be the better solution, of course.

Thanks,
Russell


Difference(Posted 2005) [#2]
Works fine. Nice. :)