Thread: Odd And Even
View Single Post
Old 10-27-2004, 01:22 PM   #3 (permalink)
inkedmn
Registered User
 
Join Date: Mar 2004
Location: Fullerton, CA
Posts: 26
inkedmn is on a distinguished road
Send a message via AIM to inkedmn
the easiest way would be something like:

Code:
if(pageindex % 2 == 0)
    // then it's even
else
    // then it's odd
the modulus operator (%) returns the remainder of any division operation. Here's a python example (since it's easier to read/understand)

Code:
>>> 3 % 2
1
>>> 14 % 7
0
because 14 divides evenly by 7, there's no remainder, but 3 doesn't divide evenly by 2, so there's a remainder of 1, etc.

hth
inkedmn is offline   Reply With Quote