0

Im getting an expected expression error in the line below that is :

 for (int i = [timeArray count] - 1; i >= 0; i-) {

specifically the i-) its messing with things and I don;t know what to do. I am trying to build a stopwatch app. Here's the entire statement:

//

- (void)showTime {
int hours = 0;
int minutes = 0;
int seconds = 0;
int hundredths = 0;
NSArray *timeArray = [NSArray arrayWithObjects:self.hun.text, self.sec.text, self.min.text, self.hr.text, nil];

for (int i = [timeArray count] - 1; i >= 0; i-) {
    int timeComponent = [[timeArray objectAtIndex:i] intValue];
    switch (i) {
        case 3:
            hours = timeComponent;
            break;
        case 2:
            minutes = timeComponent;
            break;
        case 1:
            seconds = timeComponent;
            break;
        case 0:
            hundredths = timeComponent;
            hundredths++;
            break;

        default:
            break;
    }

}
aasatt
  • 600
  • 3
  • 16

1 Answers1

1

i-) is not legal syntax. The compiler expects a literal or variable after the -.

You probably meant to write i-- or --i. Both of these statements subtract one from i. There is a difference between them, but they are both logically correct for your loop.

David Alber
  • 17,624
  • 6
  • 65
  • 71
  • Explaining the difference between the prefix and postfix operators is beyond the scope of the question, but in case you want to know, there's plenty of answers out there explaining it. Here's one: http://stackoverflow.com/questions/4445706/post-increment-and-pre-increment-concept. – David Alber Apr 25 '13 at 03:36
  • Adding one more thing, `i=i-1` or `i-=1` updates the value of `i`. If you want to change the value other than one, then you cant do with `--`. – Anoop Vaidya Apr 25 '13 at 05:32