June 2004
Intermediate to advanced
848 pages
21h 28m
English
Two statements have been changed to make them work better with enumerations: the switch statement, and the for statement.
Language designers want to make it easy to express the concept “Iterate through all the values in this enumeration type”. There was much discussion about how to modify the “for” loop statement. It was done in a clever way—by adding support for iterating through all the values in any array.
Here is the new “get all elements of an array” syntax added to the “for” statement.
// for each Dog object in the dogsArray[] print out the dog's namefor (Dog dog : dogsArray ){ dog.printName();}
This style of “for” statement has become known as the “foreach” ...
Read now
Unlock full access