Resolved Keeps exicuting the if statment

Discussion in 'iOS Programming' started by larswik, May 20, 2012.

  1. larswik, May 20, 2012
    Last edited: May 21, 2012

    larswik macrumors 68000

    Sep 8, 2006
    I need a second set of eyes here. I am building a kind of ticker tape from an array. Every even index of the array is the clients name and every odd index number is information about the client. I used the Modulus % to separate the 2 and append a string which later gets returned.

    For some reason it is always executing the if statement and not the else. I have been programming all day and I am sure it is something my brain is not catching so I thought I would ask if anyone can see why it is always evaluating to true?

    for (int i = 0; i < theArray.count; i++) {
            if ((theArray.count %2) == 0) {
                NSString *toAdd1 = [NSString stringWithFormat:@"•  %@   ",[theArray objectAtIndex:i]];
                tapeToOutput = [tapeToOutput stringByAppendingString:toAdd1];
            else {
                 NSString *toAdd2 = [NSString stringWithFormat:@"- %@    ",[theArray objectAtIndex:i]];
                tapeToOutput = [tapeToOutput stringByAppendingString:toAdd2];
    Here is a copy of the output. The array has 6 objects in it.

    EDIT: after posting, and dinner break, I looked at it again. Found the problem. It kept evaluating to true because I was using the count of my array as the condition which was 6 instead of my 'i' in my loop. Sorry

Share This Page