Printing Triangle using While Loop in C++ programming. While Loop allows code to be executed and repeat a specific block of code until the boolean condition is met.
#include<iostream.h>
#include<conio.h>
#include<string>
void main()
{
string a;
string str = "Bilal";
while(a != str) //loop stops when 'a' value Equal to 'str' value.
{
cout<<"Please Enter Password: ";
cin>>a; //user Enter value storing in 'a'.
}
cout<<"Password Correct!";
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a = 0;
while(a <= 10) //loop looping from 0 to 10.
{
if(a == 5) //if 'a' value equal to 5 then
{
cout<<"The Statement is Break on 5";
break; //break the process.
}
cout<<a<<endl;
a++; //adding 1 to 'a' value.
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a = 0;
while(a <= 10) //loop looping from 0 to 10.
{
int b = 0;
while(b <= a) //loop looping from 0 to 'a' value.
{
cout<<"* ";
b++; //adding 1 to 'b' value.
}
cout<<"\n"; //used for New Line, U also use 'endl'.
a++; //adding 1 to 'a' value.
}
getch();
}