0

Possible Duplicate:
java for loop syntax

for (File file : files){
    ...body...
}

What mean in for loop condition this line?

Community
  • 1
  • 1
Ling Tze Hock
  • 41
  • 1
  • 7

4 Answers4

2

This is java for-each (or) enhanced for loop

This means for each file in files array (or) iterable.

kosa
  • 65,990
  • 13
  • 130
  • 167
0

for (File file : files) -- is foreach loop in Java same as saying, for each file in files. Where files is an iterable and file is the variable where each element stored temporarily valid withing the for-loop scope. See http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html

Nishant
  • 54,584
  • 13
  • 112
  • 127
0

This says for-each file in a set fo files do ... (body)

Read about The For-Each Loop for more details. The examples in the link where great.

Amarnath
  • 8,736
  • 10
  • 54
  • 81
0

- This form of loop came into existence in Java from 1.5, and is know as For-Each Loop.

Lets see how it works:

For Loop:

int[] arr = new int[5];    // Put some values in

for(int i=0 ; i<5 ; i++){  

// Initialization, Condition and Increment needed to be handled by the programmer

// i mean the index here

   System.out.println(arr[i]);

}

For-Each Loop:

int[] arr = new int[5];    // Put some values in

for(int i : arr){  

// Initialization, Condition and Increment needed to be handled by the JVM

// i mean the value at an index in Array arr

// Its assignment of values from Array arr into the variable i which is of same type, in an incremental index order

   System.out.println(i);

}
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75