Exit all?

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Exit all?

Post by dunbarx » Sun Jun 22, 2014 4:16 am

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Exit all?

Post by [-hh] » Mon Jun 23, 2014 7:12 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:12 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Exit all?

Post by dunbarx » Tue Jun 24, 2014 3:50 am

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

Post Reply