convert for loop to a while loop

I'm trying to convert this code:
1
2
3
4
5
    int i = 1;
    for (int i = 1; i <= 10; i = i + 3)
    {
    cout<<"i is now :" <<i<<endl;
    }

i is now :1
i is now :4
i is now :7
i is now :10
Press any key to continue . . .


to a while loop.
1
2
3
4
5
6
7
8
 int i = 1;
    
    while (i<=10)
    {
    i = i + 3;
    i <= 10;
    cout << "i is now" << i <<endl;
    }


i is now4
i is now7
i is now10
i is now13
Press any key to continue . . .


What did i do wrong.

1
2
3
4
5
    while (i<=10)
    {
    cout << "i is now" << i <<endl;
    i = i + 3;
    }
you incremented i before using it. for loop only increments after the first cycle.
Thank you. :)
Topic archived. No new replies allowed.