c for loop
Sure! Here is an example of a for loop in C:
#include <stdio.h>
int main() {
int i;
for(i = 0; i < 10; i++) {
printf("The value of i is: %d\n", i);
}
return 0;
}
This code snippet demonstrates a basic for loop in C. The loop starts with the initialization statement int i;
, which declares and initializes the loop control variable i
to 0.
The loop continues as long as the condition i < 10
is true. On each iteration, the loop body is executed, which in this case is a single statement that prints the value of i
using the printf
function.
After each iteration, the update statement i++
increments the value of i
by 1. This ensures that the loop eventually terminates when the condition i < 10
becomes false.
The output of this code will be the numbers 0 to 9, each on a new line.
I hope this example helps! Let me know if you have any further questions.