title: Checkerboard Matrix in Objective C
body: <p>How do I produce a checkerboard matrix in objective c of n number of rows and length? (using the NSLOG to print the Output shown below)</p>
  
  <p>Example:</p>
  
  <p>Input  n = 5</p>
  
  <p>Output is </p>
  
  <pre><code>         [1 0 1 0 1
            0 1 0 1 0
            1 0 1 0 1
            0 1 0 1 0 
            1 0 1 0 1]
  </code></pre>
  
  <p>I tried this method below and it gets close. Any help would be appreciated!</p>
  
  <pre><code>-(void)checkerboardOne:(int)length {   
      NSMutableArray *squares = [NSMutableArray arrayWithObjects: nil];
      for (int y = 1 ; y &lt;= length; y++) { 
          if (y % 2) {
              for (int x = 0 ; x &lt; length; x++) {
                  if (x % 2 ) {  
                      [squares addObject:[NSString stringWithFormat:@"0"]];  
                  } else {
                      [squares addObject:[NSString stringWithFormat:@"1"]];  
                  }
              } //end row 0
          } else {
              for (int x = 0 ; x &lt; length; x++) {
                  if (x % 2 ) {
                      [squares addObject:[NSString stringWithFormat:@"1"]];
                  } else {
                      [squares addObject:[NSString stringWithFormat:@"0"]];
                  }
              } //end row 1
          }
          NSLog(@"==========\n%@", squares);
          [squares removeAllObjects];
      }
  }
  </code></pre>