14.11.2 Example

The following code is one possible implementation of the toHexString method (§20.7.14) of class Integer:


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.