We are given a 2-dimensional array `A[n,m]` with `n` rows and `m` columns and an element of that array chosen at random `R`.
Think of the array as being circular in that when we visit `A[n-1, m-1]` the next element we visit would be `A[0, 0]`. 

Starting with element `R`, we want to visit each element exactly once and call function `foo()` before moving to the next element.

The following is my first implementation but there is a bug. The bug being that if we start at row `x` somewhere between `0` and `n-1`, we will not visit element from `0` to `x-1` in that column.

```
// Init - pretend rand() always returns valid index in range
curr_row = rand();
curr_col = rand();

// Look at each column once
for (int i = 0; i < m; ++i) 
{
  for (; curr_row < n; ++curr_row) 
  {
    foo(A[curr_row][curr_col]);
  }
  curr_row = 0;
  curr_col = (curr_col + 1) % m;
}

```

What is a clean way to do this traversal such that we meet the above requirements?