Chapter 4 Iteration
Chapter 4 Iteration
COMPUTER PROGRAMMING
Iteration
ITERATION STATEMENTS
break
continue
return
Try-catch-finally
Throw
Assert
Labeled Statements
A statement may have a label
label : statement
Example:
L1: if(i> 0){
L1: System.out.println(i); // not ok Label L1 redeclared
}
L1:while(i<0){
L2:System.out.println(i); // OK
}
L1:{
int j =10;
System.out.println(j);
}
Label names exists in their own namespaces so that they do not
conflict with name of packages, classes, interfaces, methods, fields
and local variables.
The scope of a label is the statement predefined by the label.
The continue statement can be used only in for(;;), for(:), while, do-
while loops to prematurely stop the current iteration of the loop and
proceed with the next iteration, if possible.
In the case of while and do-while loops, the rest of the loop is
skipped with execution continuing with the loop condition
In the case of the for(;;) loop, the rest of the loop body is skipped
with execution continuing with the update expression.
Consider the following program: