TopBottom

Followers



Click on more
SUBSCRIBE

Enter your email address:

Delivered by FeedBurner



VIDEO

Announcement: wanna exchange links? contact me at ravikrak@yahoo.com

WHILE loop in c lang

Posted by Ravi Kumar at Thursday, September 1, 2011
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Syntax: while(test-condtion)
The test-condition is evaluated if it is non-zero
statement is executed and test-condition is re-evaluated.
This cycle continues until test-condition become zero at
which point execution resumes after .

The for statement
for(expr1; expr2; expr3)
"statement"
is equivalent to
expr1;
while(expr2)
{
"statement "
expr3;
}

The while is an entry-controlled loop.The test-
condition is evaluated and if condition is true then
the body of the loop is executed.After execution of
body the process is repeated until the test condition
becomes false and the control is transferred out of the
loop.If the body of the loop contains one or more statements
then only braces are required otherwise for a single
statement following while, braces can be dropped.

Example:
Program to find a sum of square of 10 numbers using while?

# include "stdio.h"
main( )
{
int n=1, sum=0;
while(n<=10)
{
sum=sum+n*n;
n=n+1;
}
printf("sum =%d /n",sum);
}

Share |

Labels:

0 comments:

Post a Comment