c - How is the value of this variable incremented outside of this loop? -
i have question value of j
inside nested loop.
(potentialsum=1; potentialsum<=m; potentialsum ++) { (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 , m = 25.
so when run loop aforementioned values n , m, output this:
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
my question when/how j
incremented 8, if n=7
?
this happens when potentialsum = 2
, complete code click here , copy of input click here.
thanks in advance, i'm not seeing how j
goes 7 8 outside of loop.
for (j=1;j<=n;j++) //where n 7
for( declaration ; comparison(condition checking) , increment/decrement)
after declaration, value compared, , @ end incrementing (j++
)
when j=7
check condition j<=n
true go inside loop. , @ increment j++
.
current value of j
become 8
. next time check condition j<=n
false come out of loop, j
remain 8
.
Comments
Post a Comment