Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loops  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When can you use the for/in loop? Is there a certain order you must follow ?
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ana Reyes wrote:When can you use the for/in loop? Is there a certain order you must follow ?



What's a for/in loop? Can you elaborate your question with a code snippet, as it's not clear what you mean by 'certain order'
 
Marshal
Posts: 58363
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know the Java Tutorials sections are rather short, but have you read about the for statement?
 
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ana Reyes wrote:When can you use the for/in loop? Is there a certain order you must follow ?


I think the OP may be referring to the "for each" loop...it is often read out loud as "for each A in B".

but that is a guess...
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

fred rosenberger wrote:I think the OP may be referring to the "for each" loop...it is often read out loud as "for each A in B".


@Ana: And if that's the case, then you can use it on an array, or any object that implements the Iterable interface - which includes all Lists, Sets, and Collections.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!