Patrik Nusszer :
The if compound statement is 1 block. A compound statement consists of 0 or more statements
Now if you have
if (expression) {
// do something
}
else {
// do something else
}
Is it one compound statement or two? 1 compound statement = 1 block? Just because the 2 blocks seem to belong together.
Alan Sereb :
A compound statement consists of none or more statements enclosed within a set of braces: {}.
It means that these are two compound statements because there are two sets of curle braces. The statement above could be represented just like this:
if (expression) {
// do something
}
if (!expression) {
// do something else
}
EDIT: In java some commands allow you to skip curly braces if there is only a single command to be executed (like while
or if
). For example:
if (expression) doSomething();
else doSomethingElse();
These will count as a double compound statement as well because it is treated by compiler same as the above.