The if Keyword
a == b | means does a equal b? |
a != b | means does a not equal b? |
a > b | means is a greater than b? |
a >= b | means is a greater than or equal to b? |
a < b | means is a less than b? |
a <= b | means is a less than or equal to b? |
Notice:
==means “check for equality” (are two things equal? yes or no...)versus...
=means “assignment”(evaluate the right hand side and save it into the variable on the left...)
The else Keyword
Order of Operations
Precedence Table
Comparing C-Strings
To compare blocks of text, use string.hand strcmp
Comparing chars
Remember, there is a difference between a single’’ character, and a block”” of text...
Char Literals: Single quotes: ' '
String Literals: Double quotes: " "
Nested if
If (….)
{……}
else
{
If (….)
{….}
else
{…..}
}
Notice : always use {} with the if and else
If… else if…else
Only one of option will be performance.
Comparison symbol :
And &&
Or ||
Not !
Example:
If ((a > 0) && (a <10)) // a must be greater than 0 and smeller than 10
If( (a <= 0) || (number >= 10)) a could be smeller than 0 or greater than 10
If (!(a > 0)) a must be smeller than 0
Notice:
Do not use : 10 < x < 100
Only use : 10 < x && x <100 (compile performance one logical decision by one time)
And bracketing every single relational expression which can be helpful to identify.