Page 1 of 1

Exiting from loops

Posted: Thu Apr 23, 2009 9:33 am
by grc
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

Posted: Thu Apr 23, 2009 10:05 am
by bn
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

Posted: Thu Apr 23, 2009 3:17 pm
by FourthWorld
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.

Posted: Thu Apr 23, 2009 4:51 pm
by bn
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

Posted: Sat Apr 25, 2009 2:01 pm
by Mark Smith
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

Posted: Sat Apr 25, 2009 11:27 pm
by grc
Thanks all :wink: