While statement:
• "while" test the condition before execution of the body of loop, therefore "while" is a entry controlled loop(also cknown as "top tested loop")
• The block of "while" may not be executed at all if the condition is not satisfied at the beginning.
• Syntax: of "while"
While(test condition)
{
Body of while;
}
• No semicolon is used after the condition.
• Example:
while(i<=10)
{
Printf("%d",i);
i=i+1;
}
"do...while" :
• " do..while" test the condition after execution of the body of loop,therefore "do..while" is a exit controlled loop (also known as "bottom tested loop")
• The body of "do...while". always executed at once.
• Syntax:"do...while"
do
{
Body of do...while;
}
while(test condition);
• Semicolon is used after condition.
• Example:
do
{
Printf("%d\t",10);
i++;
}
while(i<=10);
No comments:
Post a Comment