Re: By nice to the Windows user come to AppleScript please :-)
Re: By nice to the Windows user come to AppleScript please :-)
- Subject: Re: By nice to the Windows user come to AppleScript please :-)
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 10 Jan 2002 11:09:01 -0800
On 1/10/02 10:29 AM, "Andy Satori" <email@hidden> wrote:
>
Is there an equivalent construct to the VBS
>
'for each item in items ... Next'
>
Syntax in AppleScript?
>
repeat with someItem in theItems
end repeat
Frequently, and usually when the list consists not of application objects
but of strings or numbers - just a pre AppleScript list - you run into
problems because the item is not evaluated. (It is 'item x of {item 1 of
someItems, item 2 of someItems, ...}.) You can deal with that either by
using
repeat with someItem in theItems
doSomethingWith contents of someItem
end repeat
using 'contents of'. But if tiy always use this construct:
repeat with i from 1 to (count someItems)
set someItem to item i of someItems
--rest of script
end repeat
you will never, ever have any problems. so it's often simpler to stick in
the extra line using this method than worry about whether you have to check
the other method in run-time.
Now, perhaps you're wondering how to do
If somethingOrOther Then Next i (or however that is in VBA), in other
words, how to move on to the next iteration in midstream. That doesn't exist
as such in pure AppleScript, but Ray Robertson invented a wonderful
technique that does it:
repeat -- either method above
repeat 1 times
--your script
if somethingOrOther then exit repeat
--more stuff
end repeat
end repeat
--
Paul Berkowitz