简体   繁体   中英

For Loop Expression Result Unused

I'm very new to programming, and I'm working my way through an Objective-C tutorial. I'm trying to get the hang of for loops. What I'm doing is setting up a mutable array, then setting up a for loop to get the value in every 6th index of the array. (Like the value at index 6, then 12, then 18, etc). I initialized the array, and added in A - Z into it as a tester. So, A lives at index 0, Z lives at index 25. This is the for loop I wrote:

   int j;

    for (j = 0; j < [myArray count]; j + 6) {
        NSString *test = [myArray objectAtIndex:j];
        NSLog(@"%@", test);

    }

The output in the log is an endless flow of A's. I'm getting a warning on the j + 6 expression, stating "Expression result unused". Does anyone know why the above code is not working? From what I can understand (please bear with me, very new to programming) this would appear to be a valid expression for the loop. I'm failing to understand why it is not. I've browsed through all the keyword questions on here, and couldn't find any similar situations. Because of that, I'm assuming that there is probably something obvious I'm doing wrong. Any insight is much appreciated.

You want to put j = j + 6 , not just j + 6 . As it stands, you're never actually changing the value of j !

 for (j = 0; j < [myArray count]; j = j + 6)
 {
    ...
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM