Comparison of Loops in C++(For, While, Do while loop )
For Loop
1 2 3 4 5 6 7 8 9 10 | #include<iostream> using namespace std; int main() { for(int i=1; i<4; i++) { cout<<i<<endl; } cout<<"Good By"; } |
While Loop
1 2 3 4 5 6 7 8 9 10 11 12 | #include<iostream> using namespace std; int main() { int i=1; while(i<4) { cout<<i<<endl; i++; } cout<<"Good By"; } |
Do While Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<iostream> using namespace std; int main() { int i=1; do { cout<<i<<endl; i++; } while(i<4); cout<<"Good By"; } |