The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enhanced for loop - new to Java 5 or Java 6? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enhanced for loop - new to Java 5 or Java 6?" Watch "Enhanced for loop - new to Java 5 or Java 6?" New topic

Enhanced for loop - new to Java 5 or Java 6?

Dave McQueen

Joined: May 22, 2009
Posts: 29
I'm rereading parts of the SCJP study guide for Java 6 book by Bert Bates and Kathy Sierra but am confused about something:- the book says that 'As of Java 6, the for loop took on a second structure'. Wasn't the enhanced for loop new to Java 5 and not 6? I'm reading all over the web that this is the case, so is this just a typo (page 345 beginning of paragraph Using For Loops)?
As usual, your help is appreciated,

Before you criticize someone, try walking a mile in their shoes. That way you'll be a mile away from them. And you'll also have their shoes.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You are correct. The enhanced for loop was introduced in Java 5.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9464

This mistake has been reported before and soon there will be an errata for this and other such errors...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 423
From Java 5, We have Enhanced For Loop

OCPJP 6.0-81% | Preparing for OCWCD | |
I agree. Here's the link:
subject: Enhanced for loop - new to Java 5 or Java 6?
It's not a secret anymore!