LOOPS ARE BLOCK OF STATEMENTS, IN OUR PROGRAM WHICH EXECUTE REPEATATLY IN OUR PROGRAM.
SYNTAX FOR WHILE LOOP
while (condition)
{
loop body(c++ code);
}
SOURCE CODE
//WHILE LOOP IN C++
#include <iostream>
using namespace std;
int main()
{
cout<<endl;
cout<<"___WHILE LOOP IN C++___";
cout<<endl;
cout<<":SYNTAX for WHILE LOOP IN C++."<<endl;
cout<<endl;
/*
while(condition)
{
c++ statement;
}
*/
cout<<"while(condition)\n{\n c++ statement; \n}";
cout<<endl;
cout<<endl;
//initialy the value of i is 1 after that our program will cheack the condition
//which is(i<=9) if condition is true then it will run the code.
int i = 1;
while(i<=30)
{
cout<<i<<endl;
i++;
}
cout<<endl;
return 0;
}
Comments
Post a Comment