To visit every cell in a 2D array, use nested loops. The outer loop iterates through rows, the inner through columns within each row. This processes the grid row by row, left to right.
Write for (int r = 0; r < rows; r++) for outer and for (int c = 0; c < cols; c++) for inner. Access grid[r][c] inside. Every cell gets visited once in row-major order. Order matters for some algorithms but not others.
For printing or summing, any order works. For neighbor-dependent algorithms, the traversal order might need adjustment.