14. Operations on Arrays
Statements and Sub-Statements
If you were to thoroughly read the previous
program, you might think that we are trying to trick you by making an obvious
mistake: we have omitted the braces (i.e. curly brackets) around the statement
block repeated by a for
loop. It appears that this block most certainly requires the braces
because it contains more than one statement. Or, maybe not?
As loops can contain other loops, making
them nested; as sets can contain other sets as subsets; as sentences might
contain sub-sentences, so can statements contain sub-statements. But a
statement is still a single statement, no matter how many sub-statements it
contains. So an if
statement is always a single statement no matter how many sub-statements
it contains. Thus, the repeated part contains just a single statement and needs
no braces. It just happens that the if
statement from the program above
is split into two separate lines, but that has no significance whatsoever.
Similarly, the entire for
loop is also
a single statement, having one sub-statement that is an if
statement,
which in turn includes an assignment sub-statement.
The for
statement in the given program is
written in three lines. The do
while
statement is written in 5 lines and contains two sub-statements,
and each of those sub-statements is a statement by itself.