Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
How do you write an enhanced for loop

What I have tried:

I tried looking in my book but couldn't find it.
Posted
Updated 12-Jan-18 9:25am
Comments
David_Wimbley 12-Jan-18 15:10pm    
What is an enhanced for loop? This really isn't clear. You should post some code of what you've tried as at the moment, it just looks like you're trying to get people to do your homework for you.

Normal for loop
String []cars={"Nissan","Mazda","Toyota","BMW"};
for (int i=0; i < cars.length; i++) {
    System.out.println(cars[i]);
}

So with enhance for loop we can write above code as
for(String car:cars){
    System.out.println(car);
}

This i s the simple implementation of enhanced for loop.

Refer this link for more info about enhanced for loop[Oracle Bolgs^]
 
Share this answer
 
v2
Quote:
How do you write an enhanced for loop

This kind of questions is a waste of time for everyone. If you have this question, it mean that you have heaps of questions of same kind. You would better spend your time learning the language properly by reading books and follow tutos, so that all concept will come in time.
From my point of view, 'enhanced for loop' do not exist, so you should define in what a for loop is enhanced or not.
Quote:
I tried looking in my book but couldn't find it.

If it is not in the book, it is probably a misconception on your side.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900