fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // For Loop
  6. cout << "For Loop:" << endl;
  7. for (int i = 1; i <= 10; ++i) {
  8. cout << i << " ";
  9. }
  10. cout << endl << endl;
  11.  
  12. // While Loop
  13. cout << "While Loop:" << endl;
  14. int j = 1;
  15. while (j <= 10) {
  16. cout << j << " ";
  17. j++;
  18. }
  19. cout << endl << endl;
  20.  
  21. // Do-While Loop
  22. cout << "Do-While Loop:" << endl;
  23. int k = 1;
  24. do {
  25. cout << k << " ";
  26. k++;
  27. } while (k <= 10);
  28. cout << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
For Loop:
1 2 3 4 5 6 7 8 9 10 

While Loop:
1 2 3 4 5 6 7 8 9 10 

Do-While Loop:
1 2 3 4 5 6 7 8 9 10