for loop in C – free C programming tutorial

In this tutorial you you will be familiarize with one of the iteration statement that is for loop which is available in C programming language. Along with its syntax and example of for-loop.

Iteration statement

Iteration statement is defined as the set of instructions that are repeated in a sequence for specific number of times until the condition is satisfied.

When the first set of instructions is executed again, it is called an iteration.

Iteration statements are commonly known as loops.
Also the repetition or iteration processes in C programming language is done by using loop control instruction.


for loop:

Syntax of for loop:

for (initialisation of variable; condition ; decrement or increment)
  {
      statement;
     // or {block of statements}
  }

Step 1: First the counter variable gets initialized.
Step 2: In the step second condition is checked for the given condition .
If the condition returns true then the statements inside the body of for loop executes.
Otherwise for loop gets terminated and the control comes out of the loop.
Step 3: After successful execution of statements inside the body of loop, the counter variable is incremented or decremented depending on the operation (++ or – -).


Example program of for loop in C:

A code in C language to determine table of any entered number by user which is less than 100 using iteration.

// Header file which contains functions for standard input and output manipulative operation.
 #include <stdio.h> 
// Compiling of code start from main function   
 int main()  
{ 
// Declaration of local variable of data-type int
    int num,i;

// To display on console screen 
   printf(“Enter any number…… /n ”);

 // To get input from user 
   scanf(“%d”,&num);

// to check whether the entered number is lesser than 100 or not
   if(num <= 100)
     {
// i is counter variable
        for(i=1,i<=10,i++) 
          {      
             printf(“%d/n ”,num*i); 
          }
  return 0;
}

After compilation and execution of code written above you will get the following output :

OUTPUT :

Enter any number……5
5
10
15
20
25
30
35
40
45
50

This is all about the one of the iteration statement that is for-loop which is available in C programming language, along with its syntax and example of for-loop.
If you have any query please comment below.

Leave a Comment

Your email address will not be published. Required fields are marked *