repeat....until

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
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

repeat....until

Post by RossG » Tue Dec 15, 2015 5:31 pm

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?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

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

Re: repeat....until

Post by dunbarx » Tue Dec 15, 2015 6:20 pm

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

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: repeat....until

Post by RossG » Tue Dec 15, 2015 10:36 pm

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: repeat....until

Post by SparkOut » Tue Dec 15, 2015 11:21 pm

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.

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: repeat....until

Post by sritcp » Wed Dec 16, 2015 12:12 am

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
Last edited by sritcp on Wed Dec 16, 2015 1:47 am, edited 1 time in total.

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

Re: repeat....until

Post by dunbarx » Wed Dec 16, 2015 12:17 am

Sri.

Gotta lose the "until" in line 2. You do not need it, and surely do not want it. Typo?

Craig

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: repeat....until

Post by Dixie » Wed Dec 16, 2015 1:28 am

line 2 won't run anyway... Oops, sorry just noticed Craig has already picked up on that.. :oops:

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: repeat....until

Post by sritcp » Wed Dec 16, 2015 1:43 am

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

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: repeat....until

Post by RossG » Wed Dec 16, 2015 5:49 am

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

Post Reply