2. If statements
ï Structure of if statement:
ï if (true or false to check) {
instruction or output;
}
OR (if only one instruction:
ï if (true or false to check) instruction or
output;
3. Common Checks
ï x>y âx is greater than y?â
ï x<y âx is less than y?â
ï x==y âx is equal to y?â
ï x!=y âx is not equal to y?â
ï x>=y âx is greater than or equal to y?â
ï x<=y âx is less than or equal to y?â
ï x%2==0 âx is divisible by two (even).â
4. Using else
ï if (true or false to check) {
instruction or output;
}
else {
instruction or output;
}
5. else if
ï if (true or false to check) {
instruction or output;
}
else if (another check) {
instruction or output;
}
else {
instruction or output;
}
6. Compound Comparisons
ï Use parentheses if clarity is needed.
ï Use && for AND and || for OR.
ï Examples:
if (x>0 && x<100) âx is greater than 0 and
less than 100.â
If (x<0 || x>100) âx is less than 0 or greater
than 100.â
7. Negation
ï You can also check the opposite value of
a condition using !
ï Example:
ï if (!(x%2==0)) âx is odd (not even).â