Java Reference
In-Depth Information
Example 14.13-1. The do Statement
The following code is one possible implementation of the toHexString method of class
Integer :
Click here to view code image
public static String toHexString(int i) {
StringBuffer buf = new StringBuffer(8);
do {
buf.append(Character.forDigit(i & 0xF, 16));
i >>>= 4;
} while (i != 0);
return buf.reverse().toString();
}
Because at least one digit must be generated, the do statement is an appropriate control
structure.
14.14. The for Statement
The for statement has two forms:
• The basic for statement.
• The enhanced for statement
ForStatement:
BasicForStatement
EnhancedForStatement
14.14.1. The basic for Statement
The basic 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 .
BasicForStatement:
for ( ForInit opt ; Expression opt ; ForUpdate opt ) Statement
ForStatementNoShortIf:
for ( ForInit opt ; Expression opt ; ForUpdate opt ) StatementNoShortIf
ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
Search WWH ::




Custom Search