Page 1 of 1
repeat....until
Posted: Tue Dec 15, 2015 5:31 pm
by RossG
I want to use a repeat with a condition but sometimes
the condition might not be met before the limit of the
repeat loop is reached.
Is there a graceful way to exit the loop before a crash?
Re: repeat....until
Posted: Tue Dec 15, 2015 6:20 pm
by dunbarx
Hi.
Do you mean something like:
Code: Select all
on mouseUp
put 10 into temp
put 11 into foo
repeat until foo = temp
if the optionkey is down then exit to top --I put this in to get out of the loop
add 1 to foo
wait 1 -so it does not time out right away
end repeat
end mouseUp
So the manual escape is what I use when testing dangerous handlers, like this one. But is that what you meant? Usually, the right way is not to get into this sort of mess in the first place. What are you thinking of, exactly?
Craig Newman
Re: repeat....until
Posted: Tue Dec 15, 2015 10:36 pm
by RossG
What I want to do is:
repeat with x = 1 to 30 until (aVar - bVar) = 6 or until (bVar - aVar) = 6
if item x of theString is among the items of "1,2,3,4....." then
add 1 to aVar
else
add 1 to bVar
end if
end repeat (without hitting the wall!)
The difference might never be 6.
Re: repeat....until
Posted: Tue Dec 15, 2015 11:21 pm
by SparkOut
So what criteria do you want to use to end the loop? Like Craig says, use a manual escape and/or avoid an infinite loop by choosing appropriate structures/conditions.
By the way, checking whether abs(aVar - bVar) is 6 will avoid the need to check two conditions.
Re: repeat....until
Posted: Wed Dec 16, 2015 12:12 am
by sritcp
Is this what you are looking for?
Code: Select all
repeat with x = 1 to 30
if (aVar - bVar) = 6 or until (bVar - aVar) = 6 then # EDIT: delete "until" (see post below)
exit repeat
else
if item x of theString is among the items of "1,2,3,4....." then
add 1 to aVar
else
add 1 to bVar
end if
end if
end repeat
Regards,
Sri
Re: repeat....until
Posted: Wed Dec 16, 2015 12:17 am
by dunbarx
Sri.
Gotta lose the "until" in line 2. You do not need it, and surely do not want it. Typo?
Craig
Re: repeat....until
Posted: Wed Dec 16, 2015 1:28 am
by Dixie
line 2 won't run anyway... Oops, sorry just noticed Craig has already picked up on that..

Re: repeat....until
Posted: Wed Dec 16, 2015 1:43 am
by sritcp
Thanks Craig:
I just cut and pasted OP's code.
Forgot to get rid of "until" (I have edited the post to mark it)
Thanks,
Sri
Re: repeat....until
Posted: Wed Dec 16, 2015 5:49 am
by RossG
Thank you all for your help.
Looks like it will work but on other things
at the moment.
This must be one of the most helpful forums (fora ?)
on the internet. Never ceases to amaze and please
me that a solution is never more than a couple of
hours away (even when old-age-type insomnia strikes).
Once again thank you.