+ 1
What is better for or for each? Why?
2 Respostas
+ 9
for is better for usual iterative operations which have initialization, condition and incrememt/decrement.
foreach is better for working with arrays.
Please note that Java doesn't have foreach, it's called enhanced for loop.
+ 2
As stated in D A B 's response for is good for iterative operations such as a count. The foreach, or enhanced for loop, is useful for iteration through collections. Things like traversing through directories and files.