continue StatementPurpose:
- When executed in a
while,for, ordo-whilestructure, skips the remaining statements in the body of that structure, and proceeds with the next iteration of the loop.
Mechanics:
continue;
Example:
for(int i=0; i<10; i++) {if (numA == 5) {continue; // if the integer numA, is 5, continue with the next iteration of the loop.
}- /* other Java statement */
}
Usage:
- In
whileanddo-whilestructure, execution continues by evaluating the loop-continuation condition. - In the
forstructure, execution continues by incrementing the counter and then evaluating the loop continuation condition.
Restrictions:
- In most cases, a
whilestructure can be used to represent aforstructure. However, if the counter variable in awhileloop is incremented after acontinuestatement, thewhileloop will not execute in the same manner as theforloop.
email suggestions to: cs015tas@cs.brown.edu
