6.2 Traversing 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 Objective
Traverse the elements in a 1D array.
Essential Knowledge
Iteration statements can be used to access all the elements in an array. This is called traversing the array.
Traversing an array with an indexed for loop or while loop requires elements to be accessed using their indices.
Since the indices for an array start at 0 and end at the number of elements − 1, “off by one” errors are easy to make when traversing an array, resulting in an ArrayIndexOutOfBoundsException being thrown.
Last updated
Was this helpful?