• 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: Page Update and discovery of looping variable manipulations...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Page Update and discovery of looping variable manipulations...


  • Subject: Re: Page Update and discovery of looping variable manipulations...
  • From: Christopher Nebel <email@hidden>
  • Date: Wed, 31 Jul 2002 14:35:37 -0700

On Tuesday, July 30, 2002, at 09:45 AM, Michael Sullivan wrote:

thePPCGod writes:

From section titled: REPEAT WITH...
(explains REPEAT WITH command, variations, added sections below:)

SPECIAL NOTES - the variable used to count the loop
iterations can NOT be changed within the loop in a way that
will affect the loop outcome:

REPEAT WITH GenericLoopCounter FROM 1 TO 10
IF (GenericLoopCounter > 5) THEN
SET GenericLoopCounter TO 2
DISPLAY DIALOG GenericLoopCounter
END IF
END REPEAT

UNEXPECTED RESULTS WILL OCCUR: The above loop, when run,
will display the value '2' five times, but will still loop
exactly 10 times. After the loop ends, the value of
GenericLoopCounter will be at 2.

That's really interesting. I never ran into that before. It's putting
the interior of the loop as a separate scope and passing the value of
the loop counter.

That's one way to look at it, but it's much simpler and closer to the truth to look at it like this:

the original:
repeat with i from 1 to 100
something
end repeat

acts like:
repeat with __internal_loop_i from 1 to 100
set i to __internal_loop_i
something
end repeat

Whether or not this is unexpected depends on what other languages you're used to. It's explicitly mentioned in the AppleScript Language Guide.



--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Page Update and discovery of looping variable manipulations... (From: email@hidden (Michael Sullivan))

  • Prev by Date: Re: Write to file??
  • Next by Date: Display dialog + compiled scripts
  • Previous by thread: Re: Page Update and discovery of looping variable manipulations...
  • Next by thread: Test 3
  • Index(es):
    • Date
    • Thread