MarirS NasavinirS wrote:can you also tell me how enhanced for loops can help me make my code more efficient? and how are they better than traditional for loops?
Hi,
You cannot state like that. They were created for purpose mainly to iterate through collections in a "nicer", "simpler" syntax. And you're allowed basically to iterate only one way, > forward >.
Traditional "for" loop actually is more flexible.
Nicer, simpler, and more abstract. If "consistency is the hobgoblin of small minds", then Java was designed by giants. For iteration, we had array loops, while/next loops, and later Iterators.
The "for-each" construct replaces many of them and makes it easier to swap in and out different collection types without having to change the loop code.
Post by:autobot
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, the permaculture playing cards