Back    

Conditional 'If'


Negation of condition uses '!' (exclamation mark)

If an exclamation mark is put before a condition, the boolean value of the statement is negated.

if ( !condition )
{
   execute this statement if the condition is false
}


OR boolean operator

OR boolean operator (||) can be used to join two or more statements and the joint statement will only return true if one or more of the statement is true.

if ( condition1 || condition2 )
{
   execute this statement if condition1 is true or condition2 is true or both are true
}

AND boolean operator

AND boolean operator (&&) can be used to join two or more statements and the joint statement will only return true if all of the statements is true.

if ( condition1 && condition2 )
{
   execute this statement if both condition1 and condition2 are true
}