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: Axel Luttgens <email@hidden>
- Date: Thu, 25 Dec 2008 12:25:14 +0100
Le 25 déc. 08 à 11:09, Richard Rönnbäck a écrit :
Well, I have Matt's book (the first edition) with all it's
explanation about
scope, but I can't find an explanation of the variable in repeat loops
specifically.
It seems to me that repeat loops behave very much like script
objects or
handlers, with an implicit declaration of the variable as local, but
I have
never thought of repeat loops that way, so I am trying to get my
head around
what is going on.
Hello Richard,
It is much more easier to view a "repeat with loopVariable (from
startValue to stopValue)" statement as coming with a "local
loopVariable" statement as well, the latter doing nothing if a local
"loopVariable" can already be found in the current scope.
One has a similar behavior with a try statement:
set i to 10
try
set k to 1 / 0
on error i
log {my i, i}
end try
log {my i, i}
Here too, a local variable is created as soon as the "on error" part
gets invoked.
By contrast, the language tends to forbid the user from doing the same:
set i to 10
local i
--> Error: i can't be declared as local and global at the same time
and this is perhaps why the behavior of the repeat (or try) statement
seems so strange.
Axel _______________________________________________
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