For more Computer Science, Linux, C++ content visit ProgrammerCave
Follow us on Facebook | Instagram | Telegram

Contribute on Paypal

JAVA: Enhanced For Loop


Enhanced for loop was introduced in JAVA 5 as a simple way to iterate all the elements of a collection.

It is useful when scanning a array instead of using for loop. 

Here we will take a simple example to sum all the elements of an array


    public class EnhancedForLoop {

  
    public static void main(String[] args) {
       int  arr[]={3,2,4,5};
       int sum=0;
       
for(int x:arr){
       sum+=x;}
    System.out.print(sum);
    }
    }

You can also watch my video on YouTube on the same topic. Java:Enhanced For Loop
In Association with Amazon.in In Association with Amazon.in
For more Computer Science, Linux, C++ content visit ProgrammerCave
Follow us on Facebook | Instagram | Telegram

Contribute on Paypal

Popular posts from this blog

Notes : Hacking the Art of Exploitation

C++: Basic Data Types