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
#2
That's a common problem in most languages indeed. This feature is not yet implemented.
Will keep you posted.
---
Boriel
Reply
#3
boriel Wrote:That's a common problem in most languages indeed. This feature is not yet implemented.
Will keep you posted.

Thank you!

Swan, my ZX Spectrum emulator https://github.com/zoran-vucenovic/swan
Reply
#4
GOTO is our friend in some cases!!!
Duefectu
https://zx.duefectucorp.com
duefectucorp@gmail.com
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)