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

Page Update and discovery of looping variable manipulations...


  • Subject: Page Update and discovery of looping variable manipulations...
  • From: email@hidden
  • Date: Tue, 30 Jul 2002 05:47:23 EDT

For those of you just starting out who have been using my
AppleScript primer page
(www.cyberpoet.net/as/applescript.html), I just wanted to
note that the page has been updated to reflect some issues
I stumbled across last night (this a.m.) with looping
control. Additionally, the page title now reflects a
version number for the page, so updates are easier to spot.
The relevant section is posted below for everyone else's
benefit.

Best Wishes,
=-= Marc Glasgow

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.

SPECIAL NOTES (CON'T) - If a variable is used to set the
ending value of the loop, changing it's value within the
loop will NOT alter the number of times the loop executes:

SET EndValue TO 10
REPEAT WITH GenericLoopCounter FROM 1 TO EndValue
IF GenericLoopCounter > 5 then
SET EndValue TO GenericLoopCounter + EndValue
DISPLAY DIALOG ((GenericLoopCounter AS STRING)&" - "&(EndValue AS STRING)
END IF
END REPEAT
DISPLAY DIALOG (GenericLoopCounter AS STRING)&" - "&(EndValue AS STRING)

UNEXPECTED RESULTS WILL OCCUR: The above loop, when run,
will display the following output, but will loop exactly 10
times.

OUTPUT
"6 - 16"
"7 - 23"
"8 - 31"
"9 - 40"
"10 - 50"
"10 - 50"

SPECIAL NOTES (CON'T) - On the other hand, you can use a
REPEAT WHILE to accomplish changing the values of the loop
counter and the ending value within the loop without funky
results:

SET GenericLoopCounter TO 0
SET EndValue TO 5

REPEAT WHILE (GenericLoopCounter < EndValue)
IF (EndValue < 10) THEN
SET EndValue TO EndValue + 1
END IF
DISPLAY DIALOG (GenericLoopCounter as string) & " - " & (EndValue as string)
SET GenericLoopCounter TO GenericLoopCounter + 1
END REPEAT

The expected results will occur: The above loop, when run,
will display the following output, looping (10 - 0 = 10)
ten times.

OUTPUT
"0 - 6"
"1 - 7"
"2 - 8"
"3 - 9"
"4 - 10"
"5 - 10"
"6 - 10"
"7 - 10"
"8 - 10"
"9 - 10"
_______________________________________________
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.

  • Follow-Ups:
    • Re: Page Update and discovery of looping variable manipulations...
      • From: email@hidden (Michael Sullivan)
  • Prev by Date: Re: scripting OmniWeb in X
  • Next by Date: Test 3
  • Previous by thread: Re: Print setup for AppleWorks?
  • Next by thread: Re: Page Update and discovery of looping variable manipulations...
  • Index(es):
    • Date
    • Thread