How to use While loop to modify the "for loop" source code

Feb 23, 2014 at 4:30pm
Thanks for the help
Last edited on Feb 26, 2014 at 4:09am
Feb 23, 2014 at 5:00pm
closed account (zybCM4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
    int x  is 0
    int r is 0
    while( r is less than x )
    {
         increment r
    }
    return 0
}



Hope that helps.
Feb 23, 2014 at 5:27pm
If all you need to do is convert your for loops into while loops, then just keep in mind that
1
2
3
4
for (initialization; condition; action)
{
    // ...
}
is basically the same as
1
2
3
4
5
6
initialization;
while (condition)
{
    // ...
    action;
}

Topic archived. No new replies allowed.