• 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: 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
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: "Mark J. Reed" <email@hidden>)

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