Concept of FOR Loop

Definition:

  • FOR Loop is also known as Bounded loop because bounded loop executes on definite number of times.
  • FOR Loop is a Pre-Test Loop, means condition is checked before the execution of the body of statement.
  •  FOR Loop belongs from Entry-Controlled Loop, where condition is tested before entering the loop body.

Syntax of FOR Loop:

          for(initialization; condition; increment/decrement)

                 {

                     // Body of the loop

                    // Statements to be executed repeatedly

                  }

How FOR Loop Works:

Step-1: Firstly, Initialization happens then statement executed only once.
Step-2: Next, test condition is evaluated, if test condition is true the body of FOR Loop is executed. If test condition is false then FOR Loop is terminated.
Step-3: After successful execution of the body of FOR Loop, increments/decrements the loop variable.

Illustration of FOR Loop:

Program: Write a C program to print “Welcome Academic Notes” three times.

#include<stdio.h>

int main()

{

   int i=0

   for (i=1; i<=3; i++)

      {

        Printf(“Welcome Academic Notes\n”);

       }

return 0;

}

Output:

Welcome Academic Notes
Welcome Academic Notes
Welcome Academic Notes

 Application:

FOR Loop is used when we want to print/execute a block of statements repeatedly for definite number of times.
Example: If you want to print “Welcome Academic Notes” 10 times then FOR Loop control structure can be used to do program more effective and simpler.