Re: Non-executed repeat loop robs variable of value/definition
Re: Non-executed repeat loop robs variable of value/definition
- Subject: Re: Non-executed repeat loop robs variable of value/definition
- From: kai <email@hidden>
- Date: Sun, 28 Aug 2005 18:14:29 +0100
On 28 Aug 2005, at 16:54, deivy petrescu wrote:
kai,
I have the same results. But something worse happens here.
<script>
set n to 1
if n ≠ 1 then
log n
log "this"
set k to true
else
log n -- 1
log "that" -- "that"
repeat with n from 1 to 10
end repeat
end if
n
-->10
</script>
which is opposite of what I would expect following your examples.
Actually, I don't find that quite so surprising, Deivy. With the
variable 'n' having a value of 1, the statement "n ≠ 1" would
certainly evaluate to false - although any statements within the
"else" section would therefore be executed as a consequence of a
'true' evaluation. This might be distilled down to:
----------
set n to 1
if false then
-- do nothing/something else
else -- true
repeat with n from 1 to 10
end repeat
end if
n
--> 10
----------
...or:
----------
set n to 1
if true then repeat with n from 1 to 10
end repeat
n
--> 10
----------
Now for the nightmare:
<script>
set n to 1
if n = 1 then
log n -- 1
log "this" -- "this"
set k to true
else
log n
log "that"
repeat with n from 1 to 10
end repeat
end if
n
--> "AppleScript Error: The variable n is not defined."
</script>
Right. This is pretty much (give or take) what I found. Again,
boiling it down:
----------
set n to 1
if true then
-- do nothing/something else
else -- false
repeat with n from 1 to 10
end repeat
end if
n
--> "AppleScript Error: The variable n is not defined."
----------
...or:
----------
set n to 1
if false then repeat with n from 1 to 10
end repeat
n
--> "AppleScript Error: The variable n is not defined."
----------
By the way, thanks for spoiling my weekend!!!
:)
It's the least I could do, Deivy. In fact, I consider it my bounden
duty. ;)
Thanks for your reply!
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden