Home / C / While Loop in C Syntax, Flow Chart and Example

While Loop in C Syntax, Flow Chart and Example

While Loop in C: While loop is a conditional control looping statement in C which is used in iterative logics. In While Loops the et of instructions given inside the loop keeps on repeating until the condition becomes false.

While Loop Syntax

while(condition) {
   statement(s);
}

Here, statement(s) may be a single statement or a set of multiple statements.

Condition can be any expression which evaluated as an integer value and is False if results in ZERO (0) or True if results in any NON ZERO (!= 0) . The loop iterates if condition is true and terminates if condition is false.

Flow Chart of a While Loop

While loop syntax and programming tutorial

Example

#include <stdio.h>
 
int main () {

   /* Define variable */
   int a = 1;

   /* while loop printing odd numbers */
 printf("Odd Numbers Till 20 are: \n");
   while( a < 20 ) {
      printf("%d \t", a);
      a+=2;
   }
 
   return 0;
}

Output:

1  3  5  7  9  11  13  15  17  19

Also See: Sum Of Two Numbers Using While Loop

 

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

Leave a Reply

Your email address will not be published. Required fields are marked *