tampurus

1 all loops use

Dec 2nd, 2021 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. // print numbers from 1 - 10 with while, do while and for loop.
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     // while
  8.     int i=1;
  9.     cout<<"while"<<endl;
  10.     while(i<=10){
  11.         cout<<i<<" ";
  12.         i++;
  13.     }
  14.     cout<<endl<<"do while"<<endl;
  15.     i=1;
  16.     do{
  17.         cout<<i<<" ";
  18.         i++;
  19.     }while(i<=10);
  20.  
  21.     cout<<endl<<"for loop"<<endl;
  22.     for(i=1 ; i<=10 ; i++)
  23.         cout<<i<<" ";
  24.     return 0;
  25. }
  26. // output
  27. // while
  28. // 1 2 3 4 5 6 7 8 9 10
  29. // do while
  30. // 1 2 3 4 5 6 7 8 9 10
  31. // for loop
  32. // 1 2 3 4 5 6 7 8 9 10
Advertisement
Add Comment
Please, Sign In to add comment