For Loop in C Programming

  • In computer programming, a loop is a sequence of instructions that is continually repeated until a certain condition is reached.
  • A \”For\” Loop is used to repeat a specific block of code a known number of times.

Syntax

The syntax of a for loop in C programming language is

for (initial value; condition; incrementation or decrementation ) 
{
  statements;

}

Flow chart of for loop in C programming

\"For
For loop in c programming

How for loop in C Programming works?

  • The initialization statement is executed only once.
  • If the test expression is evaluated to true, statements inside the body of the for loop are executed.
  • If the test expression is evaluated to false, the for loop is terminated.
  • The incrementation/decrementation increases (or decreases) the counter by a set value.

This process goes on until the test expression is false. When the test expression is false, the loop terminates.


Write a program in C to display the first 10 natural numbers.

#include <stdio.h>
#include <conio.h>
void main()
{     
    int i;
	printf(\"The first 10 natural numbers are:\\n\");
	for (i=1;i<=10;i++)
	{      
		printf(\"%d \",i);
	}
printf(\"\\n\");
}