Java Reference
In-Depth Information
// Define x and inputMsgSize outside the while code block.
int inputMsgSize = 0;
int x = 0;
for (x = 0; x < ARRAY_SIZE ; x++) {
inputMsgSize = errorMsgs[x].msgSize;
... // as before
}
You may have noticed the similarities between the
for
loop and the
while
loop.
The
for
loop is a combination of the most common structures used in a
while
loop. For example, this is a common
while
loop structure.
initializationExpressionA;
while (testExpressionB) {
performCode;
incrementExpressionC;
}
This is combined in a
for
loop as follows:
for (initializationExpressionA; testExpressionB;
incrementExpressionC;) {
performCode;
}
T
HE SWITCH
S
TATEMENT
Structure: switch (expression) {
case (statement1):
code block1 ;
break;
case (statement2):
code block2 ;
break;
default:
code block3 ;
}