What are the for Loop in C Language ??? With Free Notes

What are the for Loop ???

for Loop is a count controlled loop in the sense that the program knows in advance how many times the loop is to be executes.

It allow us to specify three things about a loop in a single line,

  1. Setting a loop counter to an initial value.
  2. Testing the condition about loop counter.
  3. Increasing or decreasing the loop counter’s value.

Syntax,

Let’s understand the for Loop with Syntax,

for (initialization; condition; increment/decrement) {
    // code block to execute
}
  • for -> is a reserved word.
  • initialization -> is usually an assignment expression where in a loop control variable is initialized.
  • increment/decrement -> it modifies the value of the lop control variable y a certain amount.
C Language Notes

Example:

#include <stdio.h>

int main() {
    // For loop example
    for (int i = 1; i <= 5; i++) {
        printf("Iteration %d\n", i);
    }

    return 0;
}

Explanation about Example:

In this example, we used for Loop and then we initialize a “i” variable with 1. And then check the condition is i is less than or equal to 5. And with the each increment value of i will be increased.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top