+ 1

What is for each loop in java used for?

23rd Mar 2017, 9:56 AM
swara
6 Réponses
+ 17
It means you're defining each element of that array as i. So you can access the elements using i instead of array [index]. foreach loop checks all elements of a collection from first to last, so you don't need the concept of index to access elements.
23rd Mar 2017, 10:49 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 5
used to go through each element of array/list/collections one by one(Iteration)
23rd Mar 2017, 10:49 AM
Meharban Singh
Meharban Singh - avatar
+ 3
To perform an action on every item of a collection
23rd Mar 2017, 10:52 AM
T0nd3
+ 2
To iterate through every element of table.
23rd Mar 2017, 10:02 AM
Jakub Stasiak
Jakub Stasiak - avatar
0
if a variable name assigned or declared an array why it have to change it for e.g.:for(int i: array)
23rd Mar 2017, 10:19 AM
swara
- 1
h a c k e d.......................................................................................
23rd Mar 2017, 10:23 AM
Nirvana Sharma
Nirvana Sharma - avatar