How to convert for loop program into Do while loop?
How to convert for loop program into Do while loop? How to convert Do while loop into for loop program?
For loop into Do while loop conversion. Do while loop into For loop conversion.
For loop program
1 2 3 4 5 6 7 8 9 10 11 |
#include<iostream> using namespace std; int main() { int outer, innermost, s; for(outer=1; outer<=5; outer++) { cout<<"1"; cout<<endl; } } |
Output
1
1
1
1
1
How to convert for loop program into Do while loop?
Step 1:
Step 2:
Step 3:
Step 4:
Do while loop program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<iostream> using namespace std; int main() { int outer, innermost, s; outer=1; do { cout<<"1"; cout<<endl; outer++; } while(outer<=5); } |
Output
1
1
1
1