For loop Example Program in C Programming Language

C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)

1283

Program:

#include <stdio.h>
int main()
{
   int i;
   for (i=1; i<=5; i++)
   {
       printf("%d\n", i);
   }
   return 0;
}

Output:

1
2
3
4
5
Press any key to continue . . .

Explanation:

Step 1: First initialization happens and the counter variable gets initialized.
Step 2: In the second step the condition is checked, where the counter variable is tested for the given condition, if the condition returns true then the C statements inside the body of for loop gets executed, if the condition returns false then the 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 –).


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.