মঙ্গলবার, ৫ অক্টোবর, ২০১০

23. While statement

While is one kind of loop. The process to write down while statement is

While (condition)
{
Statement;
Increment or decrement;
}

Condition means a right expression and we normally use relational expression. While statement first of all check the condition if the condition is true then the program execute the while statement but if the condition false the wile statement can not execute.
Look at this program,

#include<stdito.h>
void main ()
{
int i=1;
while(i<=5)        
{
Printf(“i”);           /* statement */
i++;                      /* increment */
}
getch();
}

Output: 1 2 3 4 5

Explain: First of all I is initialize in i=1; . Then check the condition while (i<=5) so the condition is true because i=1. Then print the value of i by using printf statement (printf(“i”); ). Then the value of i is increment in (i++). Again check the while condition  and printf the value of i and increment i. whine i=6 the while condition is false so the loop is stop.

Written by arnob.

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন