< previous page page_75 next page >

Page 75
It does absolutely nothing at execution time; execution just proceeds to the next statement. It is not used often.
As the syntax template shows, a statement also can be a declaration, an executable statement, or even a block. The latter means that you can use an entire block wherever a single statement is allowed. In later chapters where we introduce the syntax for branching and looping structures, you'll see that this fact is very important.
We use blocks often, especially as parts of other statements. Leaving out a { } pair can dramatically change the meaning as well as the execution of a program. This is why we always indent the statements inside a blockthe indentation makes a block easy to spot in a long, complicated program.
Notice in the syntax templates for the block and the statement that there is no mention of semicolons. Yet the FreezeBoil program contains many semicolons. If you look back at the templates for constant declaration, variable declaration, assignment statement, and output statement, you can see that a semicolon is required at the end of each kind of statement. However, the syntax template for the block shows no semicolon after the right brace. The rule for using semicolons in C++, then, is quite simple: Terminate each statement except a compound statement (block) with a semicolon.
One more thing about blocks and statements: According to the syntax template for a statement, a declaration is officially considered to be a statement. A declaration, therefore, can appear wherever an executable statement can. In a block, we can mix declarations and executable statements if we wish:
{
    int i;
    i = 35;
    cout < i;
    float x;
    x = 14.8;
    cout < x;
}
It's far more common, though, for programmers to group the declarations together before the start of the executable statements:
{
    int i;
    float x;

    i = 35;
    cout < i;
    x = 14.8;
    cout < x;
}

 
< previous page page_75 next page >