Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exit from more than one level
#1
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":

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
Reply


Messages In This Thread
Exit from more than one level - by Zoran - 2025-04-18, 03:50 PM
RE: Exit from more than one level - by boriel - 2025-04-21, 03:27 PM
RE: Exit from more than one level - by Zoran - 2025-04-21, 03:45 PM
RE: Exit from more than one level - by Duefectu - 2025-04-23, 11:06 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)