Page 1 of 1

Exit all?

Posted: Sun Jun 22, 2014 4:16 am
by dunbarx
This came up in the use list.

Consider the addition of a command to exit a nested repeat loop:

Code: Select all

repeat with... --top level
  repeat with... --second level
    repeat with...  --third level
      repeat with...   --fourth level
        exit repeat "all" --would bring the entire nest down
      end repeat
    end repeat
  end repeat
end repeat
Now this can be effected if the entire loop structure is migrated to its own handler. In that case it is possible to exit the handler itself, which essentially does the same thing. But this is not always simple or desirable.

Perhaps it might be useful to have the option to exit a fixed number of layers:

Code: Select all

exit repeat "2" --the "2" being the repeat layer number (or perhaps the number of layers "upwards"?).
Thoughts?

Craig Newman

Re: Exit all?

Posted: Mon Jun 23, 2014 7:12 pm
by [-hh]
..........

Re: Exit all?

Posted: Tue Jun 24, 2014 3:50 am
by dunbarx
Hi, Hermann.

This is the use of flags to demarcate the various levels of nested loops. To get out of them all, I prefer moving to a separate handler.

But to exit at one level or another, flags work well, and have the advantage of marking the level in question based, as you demonstrate, on the flag's value, if you need to know that for other purposes.

I think the "exit repeat" enhancement would be a useful addition to the language. Certainly half the fun of LC is working around its limitations, or better, enhancing the LC experience with cute and clever dodges. But you are already expert in this sort of thing.

Craig