Previous Next

C While Loop

The while loop is applied whenever you need to run a code block as long as a condition holds.

Syntax

while (condition)
{
    // block of code
}

Example:

#include <stdio.h>

int main()
{
    int i = 0;
    while (i < 8)
    {
      printf("%d", i);
      i++;
    }
    return 0;
}

Output:

0 1 2 3 4 5 6 7
Previous Next