Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Things I thought I knew, but didn't - variable scope in repeat loops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Things I thought I knew, but didn't - variable scope in repeat loops



On Dec 26, 2008, at 9:53 AM, Skeeve wrote:

Explain this:

set x to "hello" -- binds 'x'

log x --> "hello"

repeat with x from 1 to 3 -- rebinds 'x'
  log x --> 1, 2, 3
  repeat with x from 10 to 30 by 10 -- rebinds 'x'
      log x --> 10, 20, 30
  end repeat
end repeat

log x --> 30

Apparently, x is bound to the value at the beginning of the loop, not at the end.


x --> "hello"
x --> 1
   x--> 10
  x --> 20
   x --> 30
x --> 2
  x--> 10
  x--> 20
  x--> 30
x --> 3
  x--> 10
  x--> 20
  x--> 30

Therefore, x winds up being equal to 30.

-- Michelle

--
If you always reach your goals, you set the bar too low. If you never reach your goals, you set the bar too high.


_______________________________________________
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
References: 
 >Re: Things I thought I knew, but didn't - variable scope in repeat loops (From: has <email@hidden>)
 >Re: Things I thought I knew, but didn't - variable scope in repeat loops (From: Skeeve <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.