d2jsp
d2jsp Forums > Off-Topic > Programmer's Haven > Java, Visual Basic, VBScript > For Loop Vs Enhance For Loop
Add Reply New Topic New Poll
ferf
#1 Apr 5 2021 06:48pm
Group: Member
Posts: 30,537
Joined: Mar 25 2009
Gold: 0.00
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.
IFAPTOBAALRUNS
#2 Apr 6 2021 01:36am
Group: Member
Posts: 832
Joined: Mar 30 2021
Gold: 0.93
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
Klexmoo
#3 Apr 6 2021 02:50am
Group: Member
Posts: 12,625
Joined: May 17 2013
Gold: 128,993.75
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
moutonguerrier
#4 Apr 12 2021 12:17pm
Group: Member
Posts: 28,392
Joined: Apr 13 2008
Gold: 33,715.69
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 Java, Visual Basic, VBScript Topic List
Add Reply New Topic New Poll