The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C while loop

The while loop, otherwise said to be a splitted for loop. Any program which are written using for loop can be written using while loop. Here, a block followed by the while loop will be executed repeatedly until the test condition is true.

while loop Syntax

Let us see how neat a syntax of while loop is

Syntax
while(test condition)
{
Body of the loop
.
}

while loop Flowchart

C for Loop

while loop Realtime

RESETICSP2LTXRXONArduinoTMDigital PWM = ~POWERANALOG IN-+UNOIOREFRESETEVE5VGNDGNDVINA0A1A2A3A4A5ICSPAREFGND1211109487563210

C program - while loop

The following example program will clearly explain the concept of while loop

while.c
#include <stdio.h>
int main()
{
int a = 1;
while(a <= 5)
{
printf("%d ", a);
a++;
}
return 0;
}
  • 1 2 3 4 5

Note:

A variable a is initialized to 1 at the time of initializing a variable. The condition a = 5 is the test condition, which is tested for every iteration. A block followed by a while loop will be executed repeatedly until the test condition is true. a++ is used to increment the value of a every time after printing the value of a.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report