这个变量的值是如何在这个循环之外递增的?

How is the value of this variable incremented outside of this loop?

我对这个嵌套循环中 j 的值有疑问。

    for (potentialSum=1; potentialSum<=m; potentialSum ++)
    {
         for (j=1;j<=n;j++)
         {
             if (potentialSum == 2) {
                 printf("j:%d in loop\n", j);
             }
         }

         C[potentialSum]=(j<=n) ? j : (-1);

         if (C[potentialSum] == -1) {
              printf("j:%d n:%d \n", j , n);
         }

    }

n = 0 and m = 25.

所以当我 运行 这个循环使用上述 n 和 m 的值时,我得到如下输出:

j:1 in loop
j:2 in loop
j:3 in loop
j:4 in loop
j:5 in loop
j:6 in loop
j:7 in loop
j:8 n:7 // Outside of loop

我的问题是 when/how j 是否递增到 8,如果 n=7?

这仅在 potentialSum = 2 时发生,完整代码请单击 here and for a copy of the input click here

提前感谢您的所有帮助,我真的不明白 j 如何在循环之外从 7 变为 8。

for (j=1;j<=n;j++)   //where n is 7

for( 声明 ; 比较(条件检查) , increment/decrement)

声明后,比较值,最后递增(j++)

j=7 时,它将检查条件 j<=n 是否为真,因此它将进入循环。然后它会递增 j++.
现在 j 的当前值将变为 8。下一次它将检查条件 j<=n 是否为假,因此它将退出循环,但 j 将保持 8.