• 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: "Mark J. Reed" <email@hidden>
  • Date: Sat, 27 Dec 2008 09:53:33 -0500

On Sat, Dec 27, 2008 at 4:39 AM, Richard Rönnbäck
<email@hidden> wrote:
> It turns out that my old habit of using unique loop variables is sound after
> all, as this example shows:

Absolutely.  Always a good practice to use different names for
different variables.  More descriptive names help make that sort of
happen automatically.  But as Ed pointed out, if for some reason you
want to confuse someone reading your code, you can have a loop counter
(local variable) with the same name as a global variable or property:


> set i to "hi, mom!"
>
> repeat with i from 1 to 10
>    say i
> end repeat
>
> say i

property i: "hi, mom!"

repeat with i from 1 to 10
   say i
end repeat

say i

--
Mark J. Reed <email@hidden>
 _______________________________________________
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: "Mark J. Reed" <email@hidden>)
 >Re: Things I thought I knew, but didn't - variable scope in repeat loops (From: Richard Rönnbäck <email@hidden>)

  • Prev by Date: Re: Thirteen Scripters Scripting
  • 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