while loop C
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("Iteration %d\n", i);
i++;
}
return 0;
}
Include the standard input-output library (
stdio.h
).Define the
main
function.Declare an integer variable
i
and initialize it to 1.Start a
while
loop with the conditioni <= 5
.Inside the loop, print the current value of
i
usingprintf
.Increment the value of
i
by 1 using thei++
shorthand.Continue looping until the condition
i <= 5
is false.End the
main
function and return 0.