fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int rec(int i = 1) {
  5. if (i == 6) {
  6. cout << endl;
  7. } else {
  8. cout << i << " ";
  9. rec(i+1);
  10. }
  11. }
  12.  
  13. int main() {
  14. for(int i = 1; i <= 5; ++i) {
  15. cout << i << " ";
  16. }
  17. cout << endl;
  18.  
  19. {
  20. int i = 0;
  21. while(i++ < 5) {
  22. cout << i << " ";
  23. }
  24. cout << endl;
  25. }
  26.  
  27. {
  28. int i = 1;
  29. do {
  30. cout << i << " ";
  31. } while (i++ < 5);
  32. cout << endl;
  33. }
  34.  
  35.  
  36. {
  37. int i = 0;
  38. loop:
  39. if (i++ < 5) {
  40. cout << i << " ";
  41. goto loop;
  42. }
  43. cout << endl;
  44. }
  45.  
  46. rec();
  47. }
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5