On Apr 25, 2012, at 9:31 AM, Michael Doub wrote:

> Can someone explain what is going on here?   This works:
> 
> Put the number of graphics of me into count
>   repeat with i =  count down to 1
>      if the short name of graphic i of me is not "TreeBG" then
>         delete graphic i
>      end if
>   end repeat
> 
> This does not:
> Put the number of graphics of me into count
>   repeat with i =  1 to count
>      if the short name of graphic i of me is not "TreeBG" then
>         delete graphic i
>      end if
>   end repeat
> 
> Why is the order significant?]

As you delete, you're reducing the "count" of items and once you've deleted an 
item, you increment the step to that + 1.  This results in skipping every other 
item and then overflowing the count since you've deleted items out from under 
yourself.  By counting backwards, you keep things sane.

Tim


_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to