• +1-617-874-1011 (US)  
  • +44-117-230-1145 (UK)  
Online Customer Service
Follow Us:

The while statement

The simplest of all looping structure in C is the While Statement. The general format of the While Statement is:

while (test condition)
{
body of the loop
}

Here the given test condition is checked and if the condition is true then the body of the Loop is executed. After the execution of the body, the test condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the test condition finally becomes false and the control is transferred out of the Loop.

On exit, the program continues with the statements immediately after the body of the Loop. The body of the Loop may have one or more statements. The braces are needed only if the body contained two are more statements.

#include <stdio.h>
#include <conio.h>
int main()
{
int x=0;
char ch;
printf("Enter a phrase whose length has to be found(terminated by enter key): \n");
while(ch!= '\n')
{
ch=getchar();
x++;
}
printf("Length is: %d",x-1);
getch();
return;
}

The above program returns the number of characters of a phrase or statement which is terminated by return key.

Below is the output of program :

while statement
While Statement Assignment Help

Topics in C Programming

PLACE ORDER NOW
 

Resources

  •   24 x 7 Availability.
  •   Trained and Certified Experts.
  •   Deadline Guaranteed.
  •   Plagiarism Free.
  •   Privacy Guaranteed.
  •   Free download.
  •   Online help for all project.
  • Need Assignment Help

Testimonial

Urgenthomework helped me with finance homework problems and taught math portion of my course as well. Initially, I used a tutor that taught me math course I felt that as if I was not getting the help I needed. With the help of Urgenthomework, I got precisely where I was weak:
Read More

Tap to Chat
Get Instant Assignment Help
Tap to Chat
Get Instant Assignment Help