While Loop:
While statement is used to execute the set of instruction in its loop untill the condition is true. It will keep on executing the commands in its loop untill the condition become false.
Syntax :
while (<expression or condtion>)
{
set of statements
.
.
n;
}
Example
To the following series with while loop.
1,2,3,4,----------10
int a;
a=1;
while(a<=10)
{
System.out.print(a);
a++;
}
if want to print this in c Language or c++ then simply write printf(a) in c and cout<<a in c++ to get the same result.
While statement is used to execute the set of instruction in its loop untill the condition is true. It will keep on executing the commands in its loop untill the condition become false.
Syntax :
while (<expression or condtion>)
{
set of statements
.
.
n;
}
Example
To the following series with while loop.
1,2,3,4,----------10
int a;
a=1;
while(a<=10)
{
System.out.print(a);
a++;
}
if want to print this in c Language or c++ then simply write printf(a) in c and cout<<a in c++ to get the same result.
No comments:
Post a Comment