Wednesday, December 16, 2024

While Loop in C Programming Language

While Loop :
While Loop is Entry Controlled Loop
Syntax of While Loop :
while(test condition) 
{
body of loop  
}
Steps of Execution :
  1. Test Condition is Evaluated First and if 'Test Condition' is True then 'body of Loop' is Executed.
  2. After Execution , Once Again 'Test Condition' is Evaluated if it is True then 'body of loop' Executed once again
  3. If Result of test condition is False Then it Continues with the statement immediately after the body of loop.
Body of Loop May have one/more Statements
  1. Curly Braces are used to Separate Block
  2. If While Loop Contain Single Statement as part of body then Pair of Braces are required
  3. Opening & Closing Braces are needed only if the body contain two / more Statements
Example of Multiple Statement as a Part of While Body
#include<stdio.h>
#include<conio.h> 
void main()
{
int i =0;
while(i<10 )
   {
   printf("Statement 1");
   printf("Statement 1");
   i++ ;
   }
getch() 
}
What is Entry Controlled Loop ?
  1. Entry is Given into the 'Loop Body' Only when the 'Entry Condition' is True
  2. In Short Condition is Tested before entering into Loop.
Illustration :
#include<stdio.h>
#include<conio.h> 
void main()
{
int n =0;
while(n<10 )
   {
   printf (" John ");
   n++ ;
   }
getch() 
}

0 comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

Copyright Notice | Link Exchange | Privacy Policy |Contact Us

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls