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?
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
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?
Code:
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.
Carivintas Winery 2 for 1 wine tasting Red Viking SMORGASBORD Buffet $12.99 Fresco Valley Cafe Greek Pasta only $16.95
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
Last edited: