#if statement

24 messages · Page 1 of 1 (latest)

jolly crescent
#

what does "if (!(i % 10) && i)" mean?

keen tundraBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

burnt sedge
#

If i mod 10 == 0 and i != 0

#

In C a expression evaluates to true if it returns a non zero value and false if it returns a zero value

jolly crescent
#

so !(1 % 10) runs if the result is false cause of the ! sign. right?
@burnt sedge

burnt sedge
#

Yes

#

The logical not (!) returns non zero if the expression its evaluating is zero and zero if the value is non zero

jolly crescent
#

so it can be re-written as if (!(i == 0) && i != 0)?

burnt sedge
#

No

#

i = 0 is assignment

#

And no

#

Thats also incorrect

#

Mod checks the remainder

#

Ie if an integer cleanly divides (0) or if doesnt (non zero)

jolly crescent
#

so if i mod 10 returns any value between 1 to 9, it becmes false?

burnt sedge
#

And yeah

jolly crescent
#

but only true when i mod 10 is 0 which means theres no remainder

burnt sedge
#

Yep

#

Essentially your code is checking to see if i is a multiple of 10

#

(0 is not a multiple hence the extra check)

jolly crescent
#

very true

#

Thank you very much @burnt sedge
It had me cnfused for a while

#

!solved