Enhanced For Loop

The enhanced for loop reads each element without managing an index. It is also called a for-each loop.

Use it when the value matters but its position does not. The loop variable receives each element in array order.

Read each element directly

public class Main {
    public static void main(String[] args) {
        int[] scores = {91, 84, 97, 88};
        int highest = scores[0];
        for (int score : scores) {
            if (score > highest) {
                highest = score;
            }
        }
        System.out.println(highest);
    }
}

Output:

97

Every score is compared with the best value seen so far. Starting with the first element also handles arrays whose values are all negative.

Assigning a new value to the loop variable does not replace the array element. Use an index loop when you need to update positions.

Complete the enhanced for loop and keep the warmest temperature seen.