While Loop :
While Loop is Entry Controlled Loop
Syntax of While Loop :
while(test condition)
{
body of loop
}
Steps of Execution :
- Test Condition is Evaluated First and if 'Test Condition' is True then 'body of Loop' is Executed.
- After Execution , Once Again 'Test Condition' is Evaluated if it is True then 'body of loop' Executed once again
- 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
- Curly Braces are used to Separate Block
- If While Loop Contain Single Statement as part of body then Pair of Braces are required
- 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 ?
- Entry is Given into the 'Loop Body' Only when the 'Entry Condition' is True
- 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()
}
Posted in: While Loop
Email This
BlogThis!
Share to Twitter
Share to Facebook
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