CHAPTER 14: Blocks and Statements Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

14.12 The for Statement

14.12.1 Initialization , 14.12.2 Iteration , 14.12.3 Abrupt Completion

The for statement executes some initialization code, then executes an Expression, a Statement, and some update code repeatedly until the value of the Expression is false .


ForStatement:

	for ( ForInitopt ; Expressionopt ; ForUpdateopt )

		Statement

ForStatementNoShortIf:

	for ( ForInitopt ; Expressionopt ; ForUpdateopt )

		StatementNoShortIf

ForInit:

	StatementExpressionList

	LocalVariableDeclaration

ForUpdate:

	StatementExpressionList

StatementExpressionList:

	StatementExpression

	StatementExpressionList , StatementExpression

The Expression must have type boolean , or a compile-time error occurs.


14.12.1 Initialization

A for statement is executed by first executing the ForInit code:


14.12.2 Iteration

Next, a for iteration step is performed, as follows:

If the value of the Expression is false the first time it is evaluated, then the Statement is not executed.

If the Expression is not present, then the only way a for statement can complete normally is by use of a break statement.


14.12.3 Abrupt Completion

Abrupt completion of the contained Statement is handled in the following manner:



Top© 1996 Sun Microsystems, Inc. All rights reserved.