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