0
For, Enhanced for.
Hello everyone! I would like to say, this is a very nice community and very usefull app for people who loves programming. I am about starting computer science university so i tghought to make some base here. I started to learn some programming languages. I am studying Java right now. Since i am a beginner i would like to ask. What's the difference between for and for each loop. I don't mean the syntax but utilization. When should i use simple for and when for each loop. All i've undersood up ti now is that for each Is used with arrays. Thank you! Have a nice day all!
1 Antwort
+ 8
the standard for has a begin value a resume condition then a statement that should be affect to resume condition or count something and it can be another thing
enhanced for loop used to traversing a collection like arrays , linked list and toe most Useful for it in hashMap where you can't traverse a map using normal loop
summary
normal for to repeat a statements many times like any other loop
enhanced for (foreach) to traverse a collection object or an array