fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int i;
  8.  
  9. // simple for loop
  10.  
  11. cout << "first loop" << endl;
  12.  
  13. for (i = 1; i < 42; i *= 2 )
  14. {
  15. cout << i << endl;
  16. }
  17.  
  18. // second loop does the same thing as the first one
  19. // but with a while loop
  20.  
  21. cout << "second loop" << endl;
  22.  
  23. i = 1;
  24. while (i<42)
  25. {
  26. cout << i << endl;
  27. i *= 2;
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
first loop
1
2
4
8
16
32
second loop
1
2
4
8
16
32