<<< Computing the average example | Index | "foreach" loop >>> |
The syntax of the enhanced for loop
for ( type variableName : arrayName )
{
statements
}
Code that prints an array of prices to the console
double[] prices = {14.95, 12.95, 11.95, 9.95}; for (double price : prices) { System.out.println(price); }
The console output
14.95 12.95 11.95 9.95
<<< Computing the average example | Index | "foreach" loop >>> |