• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
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


  • Subject: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • From: Michelle Steiner <email@hidden>
  • Date: Fri, 26 Dec 2008 10:43:13 -0700

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>)

  • Prev by Date: Re: do shell sounds
  • Next by Date: Summary: do shell sounds
  • Previous by thread: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • Next by thread: Re: do shell sounds
  • Index(es):
    • Date
    • Thread