Traversing 2D Arrays

Understand how to move around a 2D array.

We'll cover the following

Introduction

Previously, we learned about traversing 1D arrays. We only need one loop to traverse them. In the case of 2D arrays, we need both rows and columns to access a value. So, nested iteration statements are used to traverse and access all elements in a 2D array. Since 2D arrays are stored as arrays of arrays, the way 2D arrays are traversed using for loops and enhanced for loops is similar to 1D array objects.

Example

Look at the code below.

Get hands-on with 1400+ tech skills courses.