syntax of for loop in c stack over flow

for (initialization; condition; update) {
    // Code to be executed in each iteration
}
  1. Initialization: This part is executed only once at the beginning of the loop. It is used to initialize the loop control variable.

  2. Condition: This is a Boolean expression that is evaluated before each iteration. If the condition is true, the code inside the loop is executed. If it is false, the loop is terminated, and the program continues with the next statement after the loop.

  3. Code Block: The block of code inside the curly braces {} is executed if the condition is true.

  4. Update: This part is executed after each iteration of the loop. It is typically used to update the loop control variable.

  5. Repeat: After the code block is executed, the condition is checked again. If it is true, the loop continues to the next iteration; otherwise, the loop is exited, and the program proceeds to the next statement after the loop.

Example:

#include <stdio.h>

int main() {
    // Example of a for loop that prints numbers 1 to 5
    for (int i = 1; i <= 5; i++) {
        printf("%d ", i);
    }

    return 0;
}