For Loop in C

For Loop Definition

For loop in C is defined as control structure, which allows to execute the block of codes for specific number of times until the condition is false. For loop is also known as entry-controlled loop.

For Loop In C

Syntax :

for(initialization; checking; updation)
{ // block of codes }
Use of For Loop in C

Working of for Loop :

The for loop follows a very organized methodology in which it first initializes a condition, then tests the condition, and then performs conditional statements before updating data.

It has 3 parameters : Initialization, test expression and updation.

Initialization :

The conditional variable that iterates the value or aids in checking the condition is accepted as the first parameter of a basic for loop, which accepts it.

Test Expression :

The Second parameter of a fundamental for loop defines the expression , if the check expression is true, the loop iterates further; otherwise, it stops and move out of the loop.

Updation :

A basic for loop’s third parameter specifies whether to increment or decrement the conditional variable that iterates the code in response to the condition.

Body of for loop :

Body  is known as a group of statements, such as variables, functions, etc.
When an iteration is successful, these are automatically carried out, and they continue to do so until the condition is not met.

 

Run
#include <stdio.h>

int main() {

for(int i=0; i<=5; i++){

    printf("PrepInsta\n");

}

return 0;
}

Output :

PrepInsta
PrepInsta
PrepInsta
PrepInsta
PrepInsta
PrepInsta

In the above example, the value of i initialize at 0 and for every increment till the condition (i<=5) PrepInsta will be print.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription