Friday, September 4, 2020

While & do..while statements

 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

Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.

  Object Paradigm Oriented Programming  Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972.  C l...