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,
the body of the loop;
//Cprogram to print the list of natural numbers
printf("The list of the natural numbers are:\n");
The output of the above code is displayed below:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- C program to calculate the factorial of the given number
- C program to print the Fibonacci series up to n terms
- C program to print whether the given number is prime or not