Here's what the
Java Language Specification says about the for loop:
"
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 ( ForInit ; Expression ; ForUpdate )
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.
"
So the only real constraint is that the "Expression" part must return a boolean while the "ForInit" and "ForUpdate" can be valid Java statement(s) separated by commas... IN fact even the following works though you would not want to use it :-)
for (; ;) {
System.out.println("Never ending....");
}
[ October 20, 2003: Message edited by: Vinod Venkatasubramanian ]