Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd or even numbers



Folks, folks!  Stop it.  Several people have proposed the same silly
solution here.

Code that looks like this:

            if (anything) then set something to true
            else set something to false.

It's the equivalent of doing this:

          if x is 1 then set y to 1
          else if x is 2 then set y to 2
          else if x is 3 then set y to 3

etc., when what you really want is just this:

          set y to x

In this case, you can just do this:

          set myPage to (y mod 2 is 1)

Now, as Michelle points out, you can also take advantage of the fact
that if you cast a number to a boolean, the result is true if the
number is not zero.  Because of that, her version also works:

         set myPage to (y mod 2 as boolean)

Either way.  The important thing is that there's no need to use an if
test of the goal is to  assign the results of that test to a Boolean
variable.

--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
References: 
 >Re: Odd or even numbers (From: The Server Surfer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.