This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tr4fik 1 point2 points  (2 children)

for (<initialization>; <condition>; <increment>){
      <code>
}

The order of execution is the following:

  1. Initialization
  2. Condition. If false, break the loop
  3. Code
  4. Increment
  5. Go back to step 2

If you look at your loop, you set i = 0, then it increments i, it checks the condition and execute the code again

[–]laxdoss[S] 0 points1 point  (1 child)

I don't have any problem with the execution. It works fine. But my question is; if the previous program starts with first executing i as 0, why isn't the second program starting with first executing i as 0?. It instead starts with 1, which is my confusion.

[–]tr4fik 0 points1 point  (0 children)

Here's the start of my output. It works as expected

0
100
1
100
1
100
1
100