• 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: Integer comparison in repeat loops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integer comparison in repeat loops


  • Subject: Re: Integer comparison in repeat loops
  • From: Emmanuel <email@hidden>
  • Date: Sat, 17 May 2003 09:33:57 +0200

At 6:13 PM -0400 16/05/03, Richard Clark wrote:
>
>set rgbDecimalTriplet to {65024, 0, 13097}
>
>repeat with r in rgbDecimalTriplet
> display dialog "class of " & (r as string) & " " & "is " & (class of r
> as string)
> if r = 0 then
> display dialog "Yes, r is 0"
> else
> display dialog "No, r isn't 0"
> end if
>end repeat

This happens often and it is good that you know how it works.

When you enter the loop, r does not contains what you think it contains. It really contains a reference to the item 1 (or 2, etc.) of rgbDecimalTriplet: this reference was not solved yet. In many cases when you use r AppleScript will force dereferencing (for instance "r as string" obviously dereferences r), sometimes it won't.

To force dereferencing use the "contents" keyword: changing "if r=0" into "if r's contents = 0" will fix your script.

You didn't ask that, but you can also use "contents" the other way around, to write into the list:

----------------------
set theList to {1,2,3}
repeat with r in theList
set contents of r to "blah"
end
theList
--> {"blah", "blah", "blah"}
----------------------

Emmanuel
_______________________________________________
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: 
 >Integer comparison in repeat loops (From: Richard Clark <email@hidden>)

  • Prev by Date: Re: can apple GUI scripter fill out and submit a web page?
  • Next by Date: (no subject)
  • Previous by thread: Integer comparison in repeat loops
  • Next by thread: Re: Integer comparison in repeat loops
  • Index(es):
    • Date
    • Thread