Exiting from loops

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
grc
Posts: 13
Joined: Thu Apr 23, 2009 9:21 am

Exiting from loops

Post by grc » Thu Apr 23, 2009 9:33 am

Hi I was wondering if there is a way to exit out if you accidently get into one of these situations (other than force quitting and losing unsaved stuff):

Code: Select all

repeat until x = 1
   answer "Hi"
end repeat
Thanks

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Apr 23, 2009 10:05 am

Welcom grc,

Code: Select all

repeat until x = 1 
   answer "Hi" 
   wait 0 millisec with messages
end repeat
this will let you comand period or escape out of the loop
regards
Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Thu Apr 23, 2009 3:17 pm

Bernd, that would be ideal but unfortunately the command-. option isn't available for dialogs:
http://quality.runrev.com/qacenter/show_bug.cgi?id=294

The workaround is to check for escaping in the repeat loop.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Apr 23, 2009 4:51 pm

Richard,
thanks for pointing me to the bug report.

Actually what I thought the question was is how to get out of an infinite repeat loop. Not really thinking about aborting the answer dialog.
Adding 'wait 0 millisecs with messages' will get you out of an infinite repeat loop, even the one with the dialog, but only after hitting command - period quite often after the the ok button of the dialog.

So where does that leave grc?
for a normal repeat loop wait 0 etc
for a dialog in a repeat loop I suggest to put something like this

Code: Select all

 repeat until x = 1 
      answer "Hi" with "Cancel" or "OK"
      if it is "Cancel" then exit repeat
   end repeat
regards
Bernd

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Sat Apr 25, 2009 2:01 pm

One of the things I do (particularly in development) is to check for the option key during the loop:

Code: Select all

repeat until x = 1
  stuff that hopefully eventually results in x = 1 :)
  if the optionkey is down then exit repeat
end repeat
Then, when I've set off a runaway loop, I can just hold down the option key.

Best,

Mark Smith

grc
Posts: 13
Joined: Thu Apr 23, 2009 9:21 am

Post by grc » Sat Apr 25, 2009 11:27 pm

Thanks all :wink:

Post Reply