Yes, if N == 3, then indexes go from 0 to 2. Note the less-than equality operator, the body of the loop will not execute when idx == N-1 or idx > N-1.
Also if gridW == 3 then the array's index goes from 0-2. So I need to subtract one.
Iterating through all elements in an array can be written as follows:
for ( int idx = 0; idx < N; ++idx )
for ( int idx = 0; idx <= N-1; ++idx )But not:
for ( int idx = 0; idx < N-1; ++idx )