Is there any way to know the index number when using this enhanced for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is there any way to know the index number when using this enhanced for loop?

20th Apr 2016, 9:29 PM
Kim KyeongRok
Kim KyeongRok - avatar
1 Answer
+ 1
No. You would need to declare an index counter to track the index position. And if you do that, you might as well just use a regular for loop: int index = 0; for (int x : arr) { // whatever you want to do with x index++; }
23rd Apr 2016, 12:29 AM
Chris
Chris - avatar