Re: Things I thought I knew, but didn't - variable scope in repeat loops
Re: Things I thought I knew, but didn't - variable scope in repeat loops
- Subject: Re: Things I thought I knew, but didn't - variable scope in repeat loops
- From: Ed Stockly <email@hidden>
- Date: Fri, 26 Dec 2008 17:34:15 -0800
mark>>repeat with i from 1 to 10
Applescript builds a list of values (or an iterator/generator) and
sets i to the next value at the top of the loop; it doesn't look at
the current value of i to determine what the next value of i should
be. So you can do anything you want to i inside the loop and it
won't affect the loop control logic:
Yes, and it's important to note that 'i'(or whatever variable label
you use to increment in the repeat loop) is always a local variable
and is scoped and behaves the same as any other local variable....
Even in this case:
property i : "hey daddio!"
repeat with i from 1 to 10
set i to "hi, mom!"
say i
say my i
end repeat
Here it creates a local variable i, that has the same name as the
property i.
Also in this case:
global i
set i to "hey daddio!"
repeat with i from 1 to 10
log i
set i to "hi, mom!"
log i
log my i
end repeat
This is the only example I know of where two variables (a local and a
property or global) can have the same name in the same level of the
script.
But, the variable i in the repeat loop always seems to be local.
HTH,
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden