java tutorial - Java Improved for loop - java programming - learn java- java basics - java for beginners

Java improved for loop

Learn Java - Java tutorial - Java improved for loop - Java examples - Javaprograms

Improved loop for is mainly used to bypass the collection of elements, including arrays. Has been introduced since Java 5.


The syntax of the improved for loop:

for (declaration: expression)
   // Operators
click below button to copy the code. By - java tutorial - team
  • Announcement : Access to the newly declared variable block is made, which is of type compatible with the elements of the array.
  • Expression : calculates the one you need in the array of the loop. The expression can be a variable or an array method, whose call is returned by the array.

Sample Code

public class Test {

   public static void main(String args[]){
      int [] numbers = {10, 20, 30, 40, 50};

      for(int x : numbers ){
         System.out.print( x );
      String [] names ={"ran", "vicky", "surren", "shunk"};
      for( String name : names ) {
         System.out.print( name );
click below button to copy the code. By - java tutorial - team


ran, vicky, surren, shunk,

Related Searches to Java Improved for loop