Difference between While and Do-While Loop in C++
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
#include<iostream>
using namespace std;
int main()
{
system("cls");
int i=11;
cout<<"\n-------While-----------\n";
while(i<=10)
{
cout<<i<<endl;
i++;
}
i=11;
cout<<"\n-------Do While----------\n";
do
{
cout<<i<<endl;
i++;
}while(i<=10);
return 0;
}Program 2
#include<iostream>
using namespace std;
int main()
{
int choice,a,b;
system("cls");
do
{
cout<<"\n---------Menu----------"<<endl;
cout<<"1. Add\n 2.Swap \n 3. Exit"<<endl;
cout<<"\n-------------------------"<<endl;
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\nEnter two number";
cin>>a>>b;
cout<<"\nAddition is: "<<a+b;
break;
}
case 2:
{
cout<<"\nEnter two number";
cin>>a>>b;
cout<<"\nBefore Swaping: "<<a <<" "<<b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\nAfter Swaping: "<<a <<" "<<b;
break;
}
case 3:break;
default:cout<<"\nInvalid choice";
}
}while(choice!=3);
return 0;
}Program 3
#include<iostream>
using namespace std;
int main()
{
system("cls");
for (int i = 1; i <= 2; i++)
{
for (int j = 1; j <= 3; j++)
{
continue;
cout<<i <<" "<<j<<endl;
}
cout<<"Hello";
}
return 0;
} You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

