November 2013
Beginner
325 pages
9h 47m
English
A syntax note: if the code that follows the conditional expression consists of only one statement, then the curly braces are optional. So the following code is equivalent to the previous example.
BOOL isNotLegal = !((truckWeight > 0.0) && (truckWeight < 40000.0));
if (isNotLegal)
printf("Truck weight is not within legal range.\n");
However, the curly braces are necessary if the code consists of more than one statement.
BOOL isNotLegal = !((truckWeight > 0.0) && (truckWeight < 40000.0));
if (isNotLegal) {
printf("Truck weight is not within legal range.\n");
printf("Impound truck.\n");
}
Why? Imagine if you removed the curly braces.
BOOL isNotLegal = !((truckWeight > 0.0) && (truckWeight < 40000.0)); ...
Read now
Unlock full access