6.3 Enhanced for Loop for Arrays

Enduring Understanding

To manage large amounts of data or complex relationships in data, programmers write code that groups the data together into a single data structure without creating individual variables for each value.

Learning Objectives

Traverse the elements in a 1D array object using an enhanced for loop.

Essential Knowledge

An enhanced for loop header includes a variable, referred to as the enhanced for loop variable.

For each iteration of the enhanced for loop, the enhanced for loop variable is assigned a copy of an element without using its index.

Assigning a new value to the enhanced for loop variable does not change the value stored in the array.

Program code written using an enhanced for loop to traverse and access elements in an array can be rewritten using an indexed for loop or a while loop.

Last updated

Was this helpful?