Whooosh
Comment on I wish
wtry@lemm.ee 11 months ago
bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }
Comment on I wish
wtry@lemm.ee 11 months ago
bool iseven(int number){ if (number % 2 == 0){ return true; } else { return false; } }
TopRamenBinLaden@sh.itjust.works 11 months ago
I like the example in the post better. It is more clear as to what is going on to an experienced dev like me. What’s this 2 percent nonsense?
EvokerKing@lemmy.world 11 months ago
Explanation: the percent is modulus. Basically it’s just divide the first number by the second and return the remainder. If you do number % 2, it will return 1 if it is odd and 0 if it is even. For example 4/2 has a remainder of 0 and therefore is even. 3/2 has a remainder of 1, and therefore is odd.
TopRamenBinLaden@sh.itjust.works 11 months ago
Sorry I should’ve put the /s. I was just playing. But thank you for the helpful explanation, nonetheless.
Clearwatermo@lemmy.world 11 months ago
I like the example in the comment better. It is more confusing as to what is going on to an experienced dev like me. iSeven is always odd tho right?
TopRamenBinLaden@sh.itjust.works 11 months ago
I think you are on to something there. Personally, I just don’t see the advantage of using iSeven over iSix, though. I might start using iEight whenever they finally iron the kinks out of that one.
filcuk@lemmy.zip 11 months ago
Readability over obscure hacks
rustbuckett@lemmings.world 11 months ago
It’s not obscure. This is the example, with syntactic differences, for this problem in almost every programming book I’ve read. He just didn’t include newlines.
mob@lemmy.world 11 months ago
At this point, I really can’t tell who’s joking around or who’s being serious in this thread.
Shits cracking me up though reading this all as serious discussion.