Repeat Loop Question

Bob Sneidar bobs at twft.com
Fri Dec 3 14:30:24 EST 2010


I believe the reason that works you the form you use did not, is because with repeat for, the max count is evaluated as a constant, so it takes whatever value you have in tCount and stores it in it's own internal max count. Changing tCount does NOT alter that. 

However with Repeat While, the conditions are evaluated upon each loop, so it works. You will find other issues with certain forms of repeat, like repeat for each line mLine in mText. If you alter the value of mText inside the loop, you will see strange and unexpected results in mLine, because the engine evaluates mText as a location in memory, and altering mText can alter in unexpected ways what is in memory. Things get really ugly after that. 

Best to not change the conditions of a repeat loop, except in the scenario described by Colin. 

Bob


On Dec 3, 2010, at 11:15 AM, Warren Kuhl wrote:

> Colin,
> 
> Thanks....that would work.  I didn't even think to do it this way.
> 
> Have a great weekend!
> Warren
> 
> On Fri, Dec 3, 2010 at 1:09 PM, Colin Holgate <coiin at verizon.net> wrote:
> 
>> 
>> On Dec 3, 2010, at 1:59 PM, Warren Kuhl wrote:
>> 
>>> But the repeat still stops at 50.  Is there anyway to increase a repeat
>> loop
>>> maximum variable while within the loop?
>> 
>> How about:
>> 
>> put 1 into x
>> put 50 into tCount
>> repeat while x <=  tCount
>> if x = 50 then
>> put 100 into tCount
>> end if
>> add 1 to x
>> end repeat
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the Use-livecode mailing list