I am super confused what the percentage sign does in Objective C. Can someone explain to me in language that an average idiot like myself can understand?! Thanks.
% is the modulo operator, so for example 10 % 3 would result in 1.
If you have some numbers a
and b
, a % b
gives you just the remainder of a
divided by b
.
So in the example 10 % 3
, 10 divided by 3 is 3 with remainder 1, so the answer is 1.
If there is no remainder to a
divided by b
, the answer is zero, so for example, 4 % 2 = 0
.
Here's a relevant SO question about modular arithmetic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With