C for loops

C for loops is very similar to a while loops in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line. The for loop is also entry-controlled loop.

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

To understand C for loops in more depth, please watch this video tutorial.


Scroll Back to Top