Navigate to do-while

While Statement

Definition

≫while is an entry-controlled loop statement repeatedly executes a target statement as long as a given condition is true.

Syntax

while(test condition)
{

 body of the loop;

}

Some Points to be known about while


≫ The body of loop may have one or more statements.The braces are needed only if the body contains two or more statements.However,it is better to use braces even if the body has only one statement for practice.

≫The condition may be any expression,and true is any nonzero value.The loop iterates while the condition is true. When the condition becomes false, the program control passes to the line immediately following the loop.

≫If the test expression is false, the loop terminates(ends).In while loop,if the condition is not true,then the body of a loop will not be executed.






Example


#include<stdio.h>                       
void main () 
  {
    int t = 1;
   while(t<5) //executes until t value is 5
   {
      printf("value of a is %d\t",t);
      t+;  //incrementing t
   }
  getch();
} // Output : 1  2  3  4

⋙Wanna Try & Learn More Examples ??

Click Here!!

Follow us on


If you have any Queries Feel Free to Contact Us...

Email : Vintageknowledge@gmail.com


⇒Our Main Motto is your Understanding Programming in Simpler way.


 ≫ Need to get in Touch ? We'd Love to bear from you !







Happy Coding .... :)