C for Loop

Loop is the process where some part of the program repeats a or specified number of times. The part of the program repeats until it satisfies the given particular condition. We can say For Loop as an open-ended loop. In a while and do while loop, we have to write logic repeatedly. It will execute a block of statements by initializing a counter and incrementing or decrementing the counter after a particular step. This process sometimes appears to be tedious and decrease the readability of the program. For loop will help to minimize the problem with while and do while loop. With the help of For loop, we can merge all the three points i.e. initiation, condition testing, and increment or decrement.

Initiation step inside For Loop executes only once. After the initiation, the testing step is performed where the given condition is evaluated and If the condition is false then the loop terminates. But if the condition is true the body of the loop executes. The increment and decrement operator helps to update the given expression every time.

Now let’s see the syntax of For Loop,

for(initiation; condition, incremental/decrement)
{
the body of the loop;
}
Now we are going to see our first program using for loop:

The output of the above code is displayed below:
Output:

The list of the natural numbers are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
For getting more information about implementing For loop in the program, click on the following links.

 

SHARE C for Loop

You may also like...

Leave a Reply

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

Share