title: For Loop Quitting Prematurely
body: <p>Here's my loop</p>
  
  <pre><code>-(void)analyzeDataWithSearchTerm:(NSString *)searchTerm {
  
      [searchResults removeAllObjects];
  
      NSLog(@"number of items = %i", [itemIDRows count]);
  
      for (int i = 0; i &lt; [itemIDRows count]; i++) {
  
          bool foundResult = FALSE;
          if ([[[itemIDRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
              NSLog(@"ID matches %@", [itemIDRows objectAtIndex:i]);
              foundResult = TRUE;
          }
          if ([[[itemNameRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
              NSLog(@"name Matches %@", [itemNameRows objectAtIndex:i]);
              foundResult = TRUE;
          }
          if ([[[barcodeRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
              NSLog(@"barcode Matches %@", [barcodeRows objectAtIndex:i]);
              foundResult = TRUE;
          }
          if ([aliasRows objectAtIndex:i] != [NSNull null]) {
              if ([[[aliasRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
                  NSLog(@"alias Matches %@", [aliasRows objectAtIndex:i]);
                  foundResult = TRUE;
              }
          }
  
          if (foundResult) {
              NSNumber *result = [NSNumber numberWithInt:i];
              NSLog(@"found result");
              [searchResults addObject:result];
  
          } else {
              NSLog(@"no result was found this time");
          }
      }
  
      if (isScanning) {
      //do something different
      }
  }
  </code></pre>
  
  <p>The problem seems to occur if I have set "isScanning" to true (it's a bool) and run the method "analyzeDataWithSearchTerm" a second time.</p>
  
  <p>Basically this loop checks if the item is already in a purchase order. If not the item is offered to be added. Next time the item is scanned the loop runs and goes through and should detect the item as being in the purchase order. I've setup break points but the second time the loop runs (only 2 items in the order) it finds one result, gets to the line <code>foundResult = TRUE</code>, doesn't set the bool to true, and the whole method just stops. It never even makes it to </p>
  
  <p><code>if (foundResult) { }</code></p>
  
  <p>Any ideas why this might be happening?</p>