how can i check if a number is odd or even?
i would like to trigger something on even numbers.
2
4
6
8
10
ect
ect
thnx
These forums are CLOSED. Please visit the new forums HERE
odd and even numbers |
|
|
Demon Lilliehook
Registered User
Join date: 8 May 2007
Posts: 25
|
07-17-2007 08:39
how can i check if a number is odd or even?
i would like to trigger something on even numbers. 2 4 6 8 10 ect ect thnx |
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-17-2007 08:57
Something like:
if (int % 2) //odd else //even |
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
07-17-2007 08:57
I think that...
CODE
...might work. _____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224 - If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left |
|
Demon Lilliehook
Registered User
Join date: 8 May 2007
Posts: 25
|
nevermind, ....
07-17-2007 09:26
code from other language, converted to LSL, seam to work.
integer i; i = 10; if (i % 2) { llOwnerSay("$i is odd" ; } else { llOwnerSay("$i is even" ; } i = 10; if ( i&1 ) { llOwnerSay("$i is odd" ; } else { llOwnerSay("$i is even" ; } |
|
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
|
07-17-2007 12:30
how can i check if a number is odd or even? i would like to trigger something on even numbers. What exactly are you trying to accomplish? I can imagine some circumstances where this makes sense, such as in a game. But it's also the sort of tactic that novice programmers use, and it can be fine, but often isn't the best or simplest. |