Blog Introductions

In this  blog contains tutorials about  HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials,  Examples, Source code,Learning,
Tips and Software development  services. C++ Loops for loop while loop and do while loop | C++ Tutorials Bestitworriors



 C++ Loops for loop while loop and do while loop


C++ Tutorials


C++ Loops for loop while loop and do while loop | C++ Tutorials Bestitworriors - Loop execute the block of code for multiple time untill specific given condation is matched.Loops execute many times still reach given condation.C++ have following loops for loop , while loop ,do while loop.The purpose is same of all loops but the structure is different.


Some Key Points of C++ Loops


  1. Loop execute block of code for multiple times
  2. If you know how many time your loop will iterate you can use for loop instead of while loop
  3. The syntex of for loop for(int i=0;i<19;i++){ //Code }
  4. The syntex of while loop is while(i>9){//Code}
  5. Do-while loop execute first and then check the condations
  6. We can use continue and break statement in loops
  7. Continue statement use for switch the current iteration
  8. Break statement use to jump out of loop when certain condation is matched

Code




#include <iostream>
using namespace std;

int main() {


int var1 = 0;
while (var1 < 5) {
cout << var1 << "\n";
var1++;
}



int var2 = 0;
do {
cout << var2 << "\n";
var2++;
}
while (var2 < 5);




for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
cout << i << "\n";
}





for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
cout << i << "\n";
}



return 0;

}

OutPut



0
1
2
3
4
0
1
2
3
4
0
1
2
3
0
1
2
3
5
6
7
8
9



I hope You really enjoyed this blog . I try my best to make every thing is easy and helpfull to provide to public .You will get more blog about the Programing project and code . Thanks for visiting my blog if you have any querry related to this you can comment here i will try my best to response you back about C++ Loops for loop while loop and do while loop | C++ Tutorials Bestitworriors