title: Objective-C compare string object from NSArray to a string for equality
body: <p>How do I properly compare a string that I am retrieving from an NSArray to a literal string? So far, I have filled an NSArray up with three blank spaces, "   " in one method and now I am trying to replace 10 random indexes in the NSArray with the string "C10", but I don't want to replace what is there unless it is "   " still. </p>
  
  <p>Here I created the array of size 100 and filled each spot with 3 blank spaces.</p>
  
  <pre><code>-(void) initBoard{
      _board = [board initWithCapacity: 100];
      for(int i =0; i &lt; 100; i++){
          [_board addObject:@"   "];
      }
  }
  </code></pre>
  
  <p>Here is the method that I'm having problems with the equality comparison.</p>
  
  <pre><code>-(void)makeChutes: (int) numOfChutes {
      //Make argument number of Chutes randomly across the board.
      for(int i = 0; i &lt; numOfChutes || i&gt;(-100);){
          int random = arc4random_uniform(101);
          if ([[_board objectAtIndex:random] isEqual:@"   "]) {
              NSString *fString = [NSString stringWithFormat:@"C%d", 10];
              [_board replaceObjectAtIndex:random withObject:fString];
              i++;//Only increments i if 3 blank spaces were at random index..
          }
          else{//Used to attempt to stop my accidental infinite loop.
              i--;
              NSLog(@"I, loop, ran %i times.", i);//Attempt failed:-(
          }
      }
  }
  </code></pre>
  
  <p>I know the above code is a mess. In an attempt to stop the looping I made the i decrement every time it did not meet the for condition and then added an OR condition to my for loop, using ||, to try and stop it after 100 cycles. For some reason the || condition does not stop it from looping even while i is well south of -100. </p>
  
  <p>My first question is how do I properly compare the string stored in the array at index "random" with the literal string of 3 blank spaces? I also tried the method <code>isEqualToString</code>, but it worked the same.</p>
  
  <p>Secondly and less importantly, since I don't need it now, how do I properly code a bi-conditional for loop? I don't get any errors or warnings from Xcode with my for loop syntax and it compiles and runs, so I don't really get why it ignores my second conditions and keeps iterating even while <code>i</code> is <code>&lt; -100</code>.</p>