Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C for loop

    C for loop is very similar to the while loop in that it continues to process the block of code until a statement returns false, and all the conditions are defined in one line. It is an entry-controlled loop. This tutorial guides you on how to use "for loop" in the C program.

    The basic format of for loop statement is:

    Syntax:

    for ( init; condition; increment )
    {
       statement(s);
    }

    Figure - Flowchart of for loop:

    c-for

    Example of a C Program to Demonstrate for loop

    Example:

    #include<stdio.h> 
     
    int main ()
    {
      /* local variable Initialization */
      int n,times=5;;
        
       /* for loops execution */
       for( n = 1; n <= times; n = n + 1 )
       {
          printf("C for loops: %d\n", n);
       }
     
       return 0;
    }

    Program Output:

    c-for-loop


    C for loops - Video Tutorial

    Please watch this video tutorial to understand C for loops in depth.



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.