Refering to an odd number

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ac11ca
Posts: 41
Joined: Sun Mar 16, 2008 2:22 am

Refering to an odd number

Post by ac11ca » Wed Jul 23, 2008 6:48 am

Is there some way in Rev to refer to an odd/even number? Something like:

Code: Select all

If gCount is an odd number then 
    do A
else
    do B
end if


Cheers,
Adrian

Tim
Posts: 29
Joined: Wed Oct 31, 2007 12:56 pm

Post by Tim » Wed Jul 23, 2008 7:17 am

Hi,

Use

Code: Select all

if gCount mod 2 is 0 then
    --do something for an even number
else
    -- do something for an odd number
endif
Regards,

Tim

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Jul 23, 2008 9:25 am

Hi,

I do what Tim does and have created two functions. I keep them in a library, which is available to all my projects:

Code: Select all

function even theNr
  return theNr mod 2 is 0
end even

function odd theNr
  return theNr mod 2 is not 0
end odd
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply