Sometimes we need exit not only from innermost loop, but also from some outer loop (sometimes more than two levels).
As a workaround I use "do" in the outer loop and "while 1" in the inner, just to be able to use "exit do" or "exit while":
When exit from more than two levels is needed, there is no other way but to put a label and use "goto". It would be much more elegant if we could exit from more levels directly. For example, "exit do do" or "exit do do do" would exit from two or three levels of "do". I'm not sure that "exit for for for" or "exit while while" is needed; supporting "do" loop only is probably quite enough -- "do" loop is the most powerful and you can easily write any loop as a "do" loop.
What do you think?
As a workaround I use "do" in the outer loop and "while 1" in the inner, just to be able to use "exit do" or "exit while":
Code:
do
' some code
while 1
' some code
if somecondition then
exit do ' exit from two levels
end if
' some code...
if someothercondition then
exit while ' exit inner loop only
end if
' some code...
end while
' some code...
loop
When exit from more than two levels is needed, there is no other way but to put a label and use "goto". It would be much more elegant if we could exit from more levels directly. For example, "exit do do" or "exit do do do" would exit from two or three levels of "do". I'm not sure that "exit for for for" or "exit while while" is needed; supporting "do" loop only is probably quite enough -- "do" loop is the most powerful and you can easily write any loop as a "do" loop.
What do you think?
Swan, my ZX Spectrum emulator https://github.com/zoran-vucenovic/swan