Which nested loop order is row-major for rectangular grid?
Explanation
A 2D array is an array of rows, so a full traversal needs a loop inside another loop. One loop chooses a row and the other visits the values in that row. In row-major order all columns of one row are completed before the next row begins.
- A is not correct: Both loops would control the row index, so no loop ever varies the column and the separate values inside a row are never reached.
- C is not correct: Both loops would control the column index, so the row index never changes and the traversal never moves down to the other rows.
- D is not correct: Putting columns on the outside and rows on the inside is the column-major pattern, which completes all rows in one column before the next column.