Java Reference
In-Depth Information
}while( a< 20 );
Enhanced for loop
Enhanced for loop is mainly used in case of arrays.
for (declaration : expression)
// Body for enhanced for loop
Expression in the above given syntax generally represents the array which is nneeded to
lop through. This expression is either an array variable or a method call returning array.
Declaration is a block variable with the same type as the array we are accessing. This
variable has its scope within this for block with a value equal to current array element.
public class Demo {
public static void main(String args[]){
int [] values = {10, 20, 30, 40, 50};
for(int a : values ){
System.out.print( a );
System.out.print(" ");
Search WWH ::

Custom Search