How do I tell whether an integer is even or odd in a for loop?

Let’s say I do this:

for i,v in pairs(game.Players:GetChildren()) do
     -- Detect whether "i" is even or odd
end

How would I find if “i” is even or odd?’

Thanks in advance!

EDIT: This is probably so easy but I can’t think rn :joy:

6 Likes

Divide i with 2. If the result is a whole number, it is even; otherwise, it is odd (decimal).

Note: @JigglyWiggles’s solution is much more efficient.

1 Like

Modulus operator.

if i % 2 == 0 then.

maybe have to play around, I might have it wrong. If you give me a few I can test it.

Edit: this is right. If it’s even it will equal 0.

17 Likes