For Loop in C Language
×


For Loop in C Language

104

For loop in C Language is used to repeat a block of code a specific number of times.

for loop in C explained in simple terms

1Initialization

 In a for loop, initialization is similar to setting up your workspace before beginning your task, much like gathering ingredients on a table before cooking.

 It's the step where you ready any essential variables or conditions needed for the loop to run properly, marking the starting point of the loop.


2Condition

 In a for loop, you have the power to decide how many times you want to repeat loop, you might want to make a small change or adjustment before doing it again.

 Like deciding how many cookies to bake.


3 Increment/Decrement

 Each time you perform an action in a for loop, you might want to make a small change or adjustment before doing it again.

 like adding one more chocolate chip to each cookie.

Example:

#include<stdio.h>
int main()
{
	int n;
	for(n=0; n<5; n++)
	{
	printf("doing action for %d times\n", n);
	}
	return 0;
}
Output:

doing action for 0 times
doing action for 1 times
doing action for 2 times
doing action for 3 times
doing action for 4 times

In this code, the loop will repeat five times, and each time it repeats, it will print a message.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments