|
It has taken me a little while to get used to the Java 5 for loop (foreach loop) syntax, but I've gotten a lot better with it by trying to read my loops aloud. For instance, I would read the Java 5 for loop below as "For each Pizza in the list of pizzas":
List pizzaList = getPizzas();
for (Pizza pizza : pizzaList)
{
// do something with the current "pizza" reference
}
This simple trick of reading the foreach loop out loud has helped me to memorize the new syntax. Before doing this I could never remember what the for loop syntax was supposed to look like, but now I do it all the time with no problem, and yes, I do find my code much more readable than it was with the previously required Iterator syntax.
|