The while statement is used for repetition in C programming. It evaluates a test condition and executes the body of the loop if the condition is true, repeating this process until the condition becomes false. For example, a program uses a do while loop to repeatedly print whether a user-entered number is odd or even and ask if they want to continue, executing the loop body until the user enters 'n' or 'N' to quit.
The while statement is used for repetition in C programming. It evaluates a test condition and executes the body of the loop if the condition is true, repeating this process until the condition becomes false. For example, a program uses a do while loop to repeatedly print whether a user-entered number is odd or even and ask if they want to continue, executing the loop body until the user enters 'n' or 'N' to quit.
The while statement is used for repetition in C programming. It evaluates a test condition and executes the body of the loop if the condition is true, repeating this process until the condition becomes false. For example, a program uses a do while loop to repeatedly print whether a user-entered number is odd or even and ask if they want to continue, executing the loop body until the user enters 'n' or 'N' to quit.
It is used to perform repetition in C programming. The general format of the while statement is:
while (test condition)
{ body of the loop; } Here the given test condition is evaluated and if the condition is true then the body of the loop is executed. The process of repeated execution of the body continues until the test condition finally becomes false and the control is transferred out of the loop. Following diagram illustrates how while statement operates
Example program for printing the given number
is ODD or EVEN repeatedly until the user wants to quit using do while loop: # include < stdio.h > int main() { int n; char opt = 'y'; while( (opt == 'y') || (opt == 'Y')) { printf(" \n Enter an integer number: "); scanf ("%d",&n); getchar(); // to capture the enter key pressed after the entry if (n%2==0) printf("\n The number is EVEN"); else printf ("\n The number is ODD"); printf("\n Would you like to continue<y/n> : "); scanf("%c", &opt); } printf(" \n Bye Bye....."); }