Programming C : Introducing For loop.

Programming C : Introducing For loop.

Introducing For loop

Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loopbody. Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

Working Procedure :

There are three parts in the For-loop structure. They are

  1. initialization part;
  2. conditional part;
  3. increment part;

At first execute the initialization part, then execute conditional part. If condition is true then enter in the loopbody. Then execute the increment part and again execute conditional part. If condition is false then don’t execute the loopbody




For example :

#include<stdio.h>
#include<conio.h>
main()
{
            int k;
            for(k = 5; k<= 15; k = k+2)
            {
                        printf(“%4d”,k);
            }
            getch();
}

Here,

  1. Initialization part : k=5
  2. Conditional part : k<=15
  3. Increment part : k=k+2

Share this post

Comments (11)

Leave a Reply

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