• 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: Axel Luttgens <email@hidden>
  • Date: Thu, 25 Dec 2008 12:25:14 +0100

Le 25 déc. 08 à 11:09, Richard Rönnbäck a écrit :

Well, I have Matt's book (the first edition) with all it's explanation about
scope, but I can't find an explanation of the variable in repeat loops
specifically.


It seems to me that repeat loops behave very much like script objects or
handlers, with an implicit declaration of the variable as local, but I have
never thought of repeat loops that way, so I am trying to get my head around
what is going on.

Hello Richard,

It is much more easier to view a "repeat with loopVariable (from startValue to stopValue)" statement as coming with a "local loopVariable" statement as well, the latter doing nothing if a local "loopVariable" can already be found in the current scope.

One has a similar behavior with a try statement:

	set i to 10
	try
		set k to 1 / 0
	on error i
		log {my i, i}
	end try
	log {my i, i}

Here too, a local variable is created as soon as the "on error" part gets invoked.

By contrast, the language tends to forbid the user from doing the same:

	set i to 10
	local i
	--> Error: i can't be declared as local and global at the same time

and this is perhaps why the behavior of the repeat (or try) statement seems so strange.

Axel _______________________________________________
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: Richard Rönnbäck <email@hidden>)

  • Prev by Date: Re: Things I thought I knew, but didn't - variable scope in repeat loops
  • Next by Date: Re: Thirteen Scripters Scripting
  • 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