Https://www.codecademy.com/en/courses/learn-java/lessons/data-structures/exercises/for-each-loop


#1



8. For each loop


I don't understand where the variable in the "for each loop" is initialized...e.g

for (Integer temperature : weeklyTemperatures) {
System.out.println(temperature);
}

Where does the int temperature come from? It was not declared earlier..


Replace this line with your code.


#2

Believe it or not, you are declaring the variable right then and there. The loop then loops over every weekly temperature and stores it in your variable (temperature) one by one.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.