Java Reference
In-Depth Information
}while( a< 20 );
}
}
Enhanced for loop
Enhanced for loop is mainly used in case of arrays.
Syntax:
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.
Example:
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(" ");
}
System.out.print("\n");
Search WWH ::




Custom Search