• Post Reply Bookmark Topic Watch Topic
  • New Topic

Only Know Old Java. Not Familiar With New Java Code  RSS feed

 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking at the "for" loop written in new Java code:


What is its equivalence in the old style Java "for" loop?

Thank you.
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natalie:

It's probably something along the lines of:


John.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Natalie,

the old style equivalent of this new style loop would be the use of an iterator.

See this example:

for each


John
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John de Michele wrote:Natalie:

It's probably something along the lines of:


John.

John B is right. That's why it works for anything that implements Iterable - because then the iterator() method is required.
For arrays your code is accurate:
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!