August 2001
Beginner
482 pages
10h 52m
English
It is legal to leave out the braces on if statements that are only a single statement, and it is legal to nest if statements, such as the following:
if (x > y) // if x is bigger than y
if (x < z) // and if x is smaller than z
x = y; // then set x to the value in y
However, when you are writing large nested statements, this practice can cause enormous confusion. Remember, whitespace and indentation are a convenience for the programmer; they make no difference to the compiler. It is easy to confuse the logic and inadvertently assign an else statement to the wrong if statement. Listing 4.5 illustrates this problem.
Read now
Unlock full access