java - for() statement instructions order -
i create sure understand for() loop in java. java tutorials:
for (initialization; termination; increment) { statement(s) }
docs says: "the increment look invoked after each iteration through loop"
int x = 10; for(int y=2;x!=1;x++){ system.out.print(x); x=x-y; //actual x++ operation? } //prints 10 9 8 7 6 5 4 3 2
is x
incremented after system.out
, x=x-y
?
yes. x incremented after finish operation run. if things x, should increment regardless.. in each step subtract 1 x because start subtracting two, add together 1 increment.
java for-loop iteration
No comments:
Post a Comment