views:

60

answers:

3

Hi I have this code:

NSInteger *count = [monLessonArrayA count];
    for (i = 0; i < count; i++) {
        arrayVar = [monLessonArrayA objectAtIndex:i];
    }

I get an error saying i is undeclared, how can I set the objectAtIndex to i so I can loop through increasing it each time?

Thanks.

+3  A: 

Because your i is undeclared.

for (int i = 0; i < count; i++)

Also, you don't need the * for your NSInteger.

NSInteger count = [monLessonArrayA count]; 
Calvin L
Thanks! Silly me!
Josh Kahane
+2  A: 

You just forgot to declare i (and its data type) before using it in the loop:

for (int i = 0; i < count; i++) {
BoltClock
Thanks! Silly me!
Josh Kahane
@Josh: Calvin also pointed out an issue with your `count`.
BoltClock
+1  A: 

You can also use fast enumeration, which is actually faster:

for (id someObject in monLessonArrayA) {
    // Do stuff
}
Douwe Maan