General Format of a for Statement

The general form of the for statement is

for ( initialization; loopContinuationCondition; increment )
   statement

where the initialization expression initializes the loop’s control variable, loopContinuationCondition determines whether the loop should continue executing and increment increments the control variable. In most cases, the for statement can be represented by an equivalent while statement, as follows:

initialization;

while ( loopContinuationCondition )
{
   statement
   increment;
}

There’s an exception to this rule, which we’ll discuss in Section 5.7.

If the initialization expression declares the control variable (i.e., its type is specified before its name), the control variable can be used only in the body of the for statement—the control variable will be unknown outside the for statement. This restricted use of the control variable name is known as the variable’s scope. The scope of a variable specifies where it can be used in a program. Scope is discussed in detail in Chapter 6.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.183.89