For Keyword


In C programming, the 'for' keyword is used to create a for loop, which is a control flow structure that allows a block of code to be executed repeatedly for a specified number of times.

Here's an example of using the 'for' keyword to create a for loop:


for (int i = 0; i < 5; i++) {
  printf("Iteration: %d\n", i);
}

    

In this example, the for loop is created using the 'for' keyword.

The initialization section (int i = 0) is executed only once at the beginning. Then, the condition section (i < 5) is checked before each iteration.

If the condition is true, the block of code within the loop is executed. After each iteration, the increment section (i++) is executed.

The loop continues until the condition becomes false. In this case, the loop prints the value of 'i' during each iteration from 0 to 4.

The 'for' loop provides a compact and structured way to perform repetitive tasks with precise control over the loop variables and termination conditions.

It is commonly used when the number of iterations is known or when iterating over arrays or other data structures.

Loading...

Search