On a checkerboard, every other square is filled |
To accomplish this, we use the modulus operator (%) on the sum of the loop variables: if ( ( i + j ) % 2 == 0 ) { square.draw( g ); } else { square.fill( g ); } |
Basically, "x % 2 == 0" checks if x is even |