8.For each loop Where the heck did the integer temperature come from?


#1

Ok so I understand the code:

import java.util.ArrayList;

public class TemperaturesForEach {
public static void main(String[] args) {

	ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
	weeklyTemperatures.add(78);
	weeklyTemperatures.add(67);
	weeklyTemperatures.add(89); 
	weeklyTemperatures.add(94);
	
	**!*//    for (Integer temperature : weeklyTemperatures) {    \\*!  This LINE???  Integer temperature hasn't been staed anywhere yet the code works???**

		System.out.println(temperature);
	}

}

}


#2

To answer your question . Read this article by Oracle


#3

Think of temperature as a variable which takes on the value of each element in your ArrayList and moves on to the next value every iteration(run of the loop).

So the first iteration temperature would be 78 , next iteration temperature would be 67 and so on and so on.