How the check if the number is odd or even?

Is there any function that returns if the number is odd or even?

I want to use it like this:

If odd(i) then print("number %i is odd")
else ("number %i is even") end

found myself ))))))

if math.mod(i, 2) == 0 then print("even") end

1
2
3
4
5
6
        local test=999
                        if test%2 == 0 then
                                print "EVEN"
                                else
                                print "ODD"
                        end

1
2
3
4
5
if i % 2 == 0 then
print (i, " is even")
else
print (i, " is odd")
end

try this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
local function odd(num)
        if num % 2 == 0 then 
           return false 
        else 
           return true
        end
end
 
local i = 9
if odd(i) then 
    print("number ".. i .." is odd")
else 
    print("number ".. i .." is even")
end
views:1715 update:2012/2/9 11:37:26
corona forums © 2003-2011