what does this mean?
what does the ! in the parenthesis mean? i thought if statement should compare 2 variables.Code:if(somenumber == 0) { blah blah } if(!(somenumber%2)) { blah blah } else if(somenumber%2) { blah blah }
what does this mean?
what does the ! in the parenthesis mean? i thought if statement should compare 2 variables.Code:if(somenumber == 0) { blah blah } if(!(somenumber%2)) { blah blah } else if(somenumber%2) { blah blah }
Last edited by Kevin Nguyen; 10-24-2013 at 08:10 PM.
The general form of the if statement is
if (expression)
statement;
Note that expression need not compare two values, the only thing that is checked is expression (or more correctly the result of the expression). If the expression evaluates to "true" (not zero) then statement is executed. So although expression might be used to compare two or more values it doesn't have to do so. The expression may even be a constant, e.g. if (1) statement;
! means not. Like if (True) and if(!true). Hope you get it.