• 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: Applescript-users Digest, Vol 2, Issue 490
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applescript-users Digest, Vol 2, Issue 490


  • Subject: Re: Applescript-users Digest, Vol 2, Issue 490
  • From: Jonathan Levi MD <email@hidden>
  • Date: Tue, 26 Jul 2005 18:04:13 -0400

Date: Tue, 26 Jul 2005 01:12:13 -0500
From: Jim Witte <email@hidden>
Subject: Way to get functionality of C's 'continue' or HC 'next
	repeat'	without using if construct?
To: Applescript <email@hidden>
Message-ID: <email@hidden>

   I want to write a script that does the following

repeat with i from 1 to numDocs
         set docName to (name of document i)
         if (docName does not contain "blah") then
             continue repeat
         end if
         set tURL to (URL of document i)
         [..]
end repeat

   But that looks kind of ugly to me  (what I really want to *say* is
"if this condition isn't true, skip this data"...


"continue repeat" isn't valid AppleScript, of course. In this case, there
is a parallel to usual English-composition admonition to avoid double-negatives; better to say, "If this condition is true, perform the procedure using this data":


    set mylist to {2,4,6}
    repeat with i from 1 to 3
    if (item i of mylist is not 4) then continue repeat --  error
    log item i of mylist
    end repeat

Alternative:

    set mylist to {2, 4, 6}
    repeat with i from 1 to 3
        if (item i of mylist is 4) then log item i of mylist
    end repeat
    (*4*)

You could use a more complex filter:

    set mylist to {2, 4, 6}
    repeat with i from 1 to 3
        if isPerfectSquare(i) then log item i of mylist
    end repeat

If there's a "drop dead" value of i, then you can use exit:

    set mylist to {2, 4, 6}
    repeat with i from 1 to 3
	if item i of mylist „ myDropDeadValue then exit repeat
	log item i of mylist
    end repeat

Moral: One can achieve legibility and even (sometimes) elegance with AppleScript, by taking AppleScript on its own terms. </sermon>

Jonathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • MySQL Question
      • From: Steve Suranie <email@hidden>
    • Re: Applescript-users Digest, Vol 2, Issue 490
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)
  • Next by Date: Automatically launch Citrix client from Safari
  • Previous by thread: Re: set myList to myList & ...(Applescript-users Digest, Vol 2, Issue 489)
  • Next by thread: Re: Applescript-users Digest, Vol 2, Issue 490
  • Index(es):
    • Date
    • Thread