Back to Course
Loops

Understanding While loop in C

What is a while Loop?

The while loop repeats a block of code as long as a given condition remains true. It's an entry-controlled loop — the condition is checked before each iteration.

Syntax

while (condition) {
    // statements
}

Example

int i = 1;
while (i <= 5) {
    printf("%d ", i);
    i++;
}
// Output: 1 2 3 4 5

If the condition is false to begin with, the loop body never executes.

Ready to master real-world C Programming development?

Learn C Programming hands-on with mentor-led, live sessions.

Explore Course