Choose a branch using if, else and logical expressions.
Understand the concept
An if statement executes its body when its expression is nonzero. Use comparison operators such as >= and <= to produce a true or false result. The && operator requires both conditions to be true; || accepts either condition.
Read the example
The complete program appears below. Read it first, predict the output, then run it.
Expected output
Check temperature
Practise
Test the values -1, 0, 40 and 41. Explain why the boundary values matter.
Common mistake
Use == to compare equality. A single = assigns a value and can silently change a condition.