For Loop in C With Example

For Loop in C With Example


This loop is utilized when the number of iterations is known. The first part is to initialize the variable; the second contains the condition to show the iteration number. The third part is to increment. In the body of a loop, we can apply conditions, etc.

For (initialize variable; condition; increment)


  Body of for loop


Example 1

To explain the concept of for loop, you need to have any text editor in Ubuntu. We will use the one that is present by default. We will write the c code and will save this file. We have used a single condition of the For loop. An array of float values is introduced here. If we want to print all these values, we will use for loop in this situation. It will start from the zero indexes and till it reaches the 8th index.