Example of for loop

The following program illustrates how to use for loop in C:

C




// C program to demonstrate for loop
#include <stdio.h>
 
int main()
{
    int gfg = 0;
   
    // 'gfg' <= 5 is the check/test expression
    // The loop will function if and only if 'gfg' is less
    // than 5
    //'gfg++' will increments it's value by this so that the
    // loop can iterate for further evaluation
 
      // conditional statement
    for (gfg = 1; gfg <= 5; gfg++)
    {
        // statement will be printed
        printf("w3wiki\n");
    }
 
    // Return statement to tell that everything executed
    // safely
    return 0;
}


Output

w3wiki
w3wiki
w3wiki
w3wiki
w3wiki

C for Loop

In C programming, loops are responsible for performing repetitive tasks using a short code block that executes until the condition holds true. In this article, we will learn about for loop in C.

Similar Reads

for Loop in C

The for loop in C Language provides a functionality/feature to repeat a set of statements a defined number of times. The for loop is in itself a form of an entry-controlled loop....

Syntax of for Loop

for(initialization; check/test expression; updation) { // body consisting of multiple statements }...

Structure of for Loop

The for loop follows a very structured approach where it begins with initializing a condition then checks the condition and in the end executes conditional statements followed by an updation of values....

How for Loop Works?

The working of for loop is mentioned below:...

Flowchart of for Loop

C for Loop Flow Diagram...

Example of for loop

The following program illustrates how to use for loop in C:...

Nested for loop in C

...

Special Conditions

C provides the feature of a nested loop where we can place a loop inside another loop....

Advantages of for Loop

1. for loop without curly braces...

Disadvantages of for Loop

...

Conclusion

...

FAQs on for loops in C

There are certain advantages of using for loops in C as mentioned below:...