• 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: How to do a goto with Applescript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to do a goto with Applescript?


  • Subject: Re: How to do a goto with Applescript?
  • From: Stan Cleveland <email@hidden>
  • Date: Mon, 10 Jan 2011 12:11:45 -0800

On Jan 10, 2011, at 9:31 AM, Alex Zavatone wrote:

Most of the deep nesting in an AppleScript repeat loop could be avoided if there were an 'next repeat' command in AppleScript.

There is a way to do that if you're looping through an index.  Simply add 1 to the index.  But yes, next repeat would be rather nice.

Hi Alex,

Modify the index in an AS repeat loop as much as you like, but when the next iteration starts AS will restore it to its prior value before incrementing it. Both of the following will loop 10 times, period.

repeat with i from 1 to 10
display dialog i
set i to i + 2
end repeat

repeat with i from 1 to 10
display dialog i
end repeat

I truly wish that that weren't so. However, it *does* prevent interference with the loop index by accidentally misusing or reusing the index variable, as in the case below. I've actually done this and, despite my own stupidity it works correctly, thanks to AS's internal tracking and scoping of indices. (But don't do it on purpose! This disrupts the readability of the code.)

repeat with i from 1 to 10
display dialog "Outer " & i
repeat with i from 1 to 2
display dialog "Inner " & i
end repeat
end repeat

Stan C.
 _______________________________________________
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

  • Follow-Ups:
    • Re: How to do a goto with Applescript?
      • From: KOENIG Yvan <email@hidden>
References: 
 >Re: How to do a goto with Applescript? (From: Skeeve <email@hidden>)
 >Re: How to do a goto with Applescript? (From: "Mark J. Reed" <email@hidden>)
 >Re: How to do a goto with Applescript? (From: Luther Fuller <email@hidden>)
 >Re: How to do a goto with Applescript? (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: How to do a goto with Applescript?
  • Next by Date: Re: How to do a goto with Applescript?
  • Previous by thread: Re: How to do a goto with Applescript?
  • Next by thread: Re: How to do a goto with Applescript?
  • Index(es):
    • Date
    • Thread