d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > For Loop Vs Enhance For Loop
Add Reply New Topic New Poll
Member
Posts: 31,292
Joined: Mar 25 2009
Gold: 0.00
Apr 5 2021 06:48pm
What are situations where you should use one above another?
I mostly use regular for loops, but i'm wondering in what situations is each more efficient than the other? thanks guys.
Member
Posts: 832
Joined: Mar 30 2021
Gold: 0.93
Apr 6 2021 01:36am
I've never heard of an "Enhance For Loop", wtf is this lol

This post was edited by IFAPTOBAALRUNS on Apr 6 2021 01:36am
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Apr 6 2021 02:50am
for-each loops is just syntactic sugar that handles looping over the iterator until it's empty, there's nothing improved other than being easier to read
Member
Posts: 30,945
Joined: Apr 13 2008
Gold: 11,996.69
Apr 12 2021 12:17pm
Quote (IFAPTOBAALRUNS @ Apr 6 2021 03:36am)
I've never heard of an "Enhance For Loop", wtf is this lol


op is usually refering to Java

Code
List<int> list = {1,2,3};

// regular for loop
for(int i = 0; i < list.length() ; i++) {
System.out.println( list[i] );
}


// enhanced for loop in Java
for (int item : list) {
System.out.println( item );
}


This post was edited by moutonguerrier on Apr 12 2021 12:20pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll