简体   繁体   English

对于循环表达式结果未使用

[英]For Loop Expression Result Unused

I'm very new to programming, and I'm working my way through an Objective-C tutorial. 我对编程非常陌生,并且正在通过Objective-C教程进行工作。 I'm trying to get the hang of for loops. 我正在尝试摆脱for循环的困扰。 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. 我正在做的是设置一个可变数组,然后设置一个for循环以在数组的第6个索引中获取值。 (Like the value at index 6, then 12, then 18, etc). (类似于索引6、12、18等的值)。 I initialized the array, and added in A - Z into it as a tester. 我初始化了数组,并在其中添加A-Z作为测试器。 So, A lives at index 0, Z lives at index 25. This is the for loop I wrote: 因此,A位于索引0,Z位于索引25。这是我编写的for循环:

   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. 日志中的输出是A的无尽流。 I'm getting a warning on the j + 6 expression, stating "Expression result unused". 我在j + 6表达式上收到警告,指出“表达式结果未使用”。 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 . 您想放j = j + 6 ,而不仅仅是j + 6 As it stands, you're never actually changing the value of j ! 就目前而言,您实际上从未更改过j的值!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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