Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // print numbers from 1 - 10 with while, do while and for loop.
- #include <iostream>
- using namespace std;
- int main()
- {
- // while
- int i=1;
- cout<<"while"<<endl;
- while(i<=10){
- cout<<i<<" ";
- i++;
- }
- cout<<endl<<"do while"<<endl;
- i=1;
- do{
- cout<<i<<" ";
- i++;
- }while(i<=10);
- cout<<endl<<"for loop"<<endl;
- for(i=1 ; i<=10 ; i++)
- cout<<i<<" ";
- return 0;
- }
- // output
- // while
- // 1 2 3 4 5 6 7 8 9 10
- // do while
- // 1 2 3 4 5 6 7 8 9 10
- // for loop
- // 1 2 3 4 5 6 7 8 9 10
Advertisement
Add Comment
Please, Sign In to add comment