• 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: Re: Repeat With question (newbie level)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: Repeat With question (newbie level)


  • Subject: Re: Re: Repeat With question (newbie level)
  • From: John W Baxter <email@hidden>
  • Date: Wed, 14 Feb 2001 20:21:18 -0800

At 18:11 -0800 2/14/01, Michelle Steiner wrote:
>On 2/14/01 5:52 PM, email@hidden <email@hidden> wrote:
>
>>There is a caveat with this approach (which is a correct and very good
>>approach BTW, being standard Applescript and all). A script will demonstrate:
>>
>>set alphaList to {"a", "b", "c"}
>>
>>repeat with aLetter in alphaList
>> if aLetter is equal to "b" then beep 1
>> if aLetter is "b" then beep 1
>> if aLetter = "b" then beep 1
>> if aLetter is equal to "b" then beep 1
>> if (aLetter as string) is equal to "b" then beep 1 -- only this line
>>makes a beep
>>end repeat
>
>This is true, but I don't understand why. Look at this:
>
>set alphaList to {"a", "b", "c"}
>
>repeat with aLetter in alphaList
> if aLetter is equal to "b" then beep 1
> if aLetter is "b" then beep 1
> if aLetter = "b" then beep 1
> if aLetter is equal to "b" then beep 1
> if (aLetter as string) is equal to "b" then beep 1 -- only this line
>makes a beep
>end repeat

We've done this before. The variable aLetter does not become in turn "a"
then "b" then "c" as it appears it should. Instead, it becomes
item 1 of alphaList
then item 2 of alphaList
then item 3 of alphaList

We need to turn those into the actual letter. In the above code, only the
as string
does that job.

We can change the script just a little and it will be a lot noisier:

set alphaList to {"a", "b", "c"}

repeat with aLetterItem in alphaList
set aLetter to contents of aLetterItem
if aLetter is equal to "b" then beep 1
if aLetter is "b" then beep 1
if aLetter = "b" then beep 1
if aLetter is equal to "b" then beep 1
if (aLetter as string) is equal to "b" then beep 1
end repeat

Now, aLetter really is a one letter string each time.

--John




--
John Baxter email@hidden Port Ludlow, WA, USA


  • Follow-Ups:
    • Re: Repeat With question (newbie level)
      • From: g3pb <email@hidden>
References: 
 >Re: Re: Repeat With question (newbie level) (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: A little off topic
  • Next by Date: 'explode' quark document into pages
  • Previous by thread: Re: Re: Repeat With question (newbie level)
  • Next by thread: Re: Repeat With question (newbie level)
  • Index(es):
    • Date
    • Thread