Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualfastcall22

Posted 15 August 2012 - 01:58 PM

Also if gridW == 3 then the array's index goes from 0-2. So I need to subtract one.

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.

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 )

#1fastcall22

Posted 15 August 2012 - 01:57 PM

Also if gridW == 3 then the array's index goes from 0-2. So I need to subtract one.

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. Iterating through the 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 )

PARTNERS