Re: Impossible "If"?
Re: Impossible "If"?
- Subject: Re: Impossible "If"?
- From: Deivy Petrescu <email@hidden>
- Date: Sat, 12 May 2001 22:26:42 -0400
On 5/11/01 10:00 AM, "Andy Bachorski" <email@hidden> wrote:
> The above repeat statement will cause the count command to be executed for
> each iteration of the repeat statement. Not (too) big of a issue in the
> above case where the list is a local variable. But consider the following
> tell app "Finder"
> repeat with i from 1 to count of files in someFolder
> set anItem to file i of someFolder
> -- do something
> end repeat
> end tell
> In this script, a count command will be sent to the Finder for each
> iteration of the repeat loop. Depending on how many items are in the
> folder, this could significantly slow down the script. Better to
count once
> before the repeat.
No, apparently that's not true, Andy. It only counts once, before doing the
repeat loop. ..
Paul Berkowitz
It is not true. It does not count every time.
Here:
----
tell application "Finder"
repeat with zfolder in folder "Linux Boot:Test:" --Test has
six folders, New Folder to New Folder 5
move zfolder to folder "Linux Boot:Ztest:" -- fails
on item 4. Not counted every loop
end repeat
end tell
------
This one however is fine:
-----
set oldlist to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
set newlist to {}
repeat with i in oldlist
set z to count of items in oldlist
log z
log class of i
if (i as string) = "7" then beep
set end of newlist to i
log newlist
set oldlist to rest of oldlist
log oldlist
end repeat
-----
Finder lists are different, feel like list, smell like list but
behave like records ... 8-)
-----
And this fails too
----
set oldlist to {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
set newlist to {}
repeat with i from 1 to count of items in oldlist
set z to count of items in oldlist
log z
set end of newlist to item i of oldlist -- fails in item 6.
So it is not counting
log newlist
set oldlist to rest of oldlist
log oldlist
end repeat
----
The moral is , if you are deleting or moving items from a list to it
backwards or you are bound to err. And no your computer is not
calculating the count of items every time, except on the last script
where I directed it do do so.
Deivy Petrescu
http://www.dicas.com
Tips for your Mac.
Dicas para o seu Mac.
mailto:email@hidden
mailto:email@hidden