0% found this document useful (0 votes)
42 views2 pages

FOR LOOP in C

Looping is process of performing some task repeatedly till certain condition is met loops are very best way to perform repeated task. looping are very efficient lets see what will be the approach, of writing your name 10 times, without using looping function

Uploaded by

ayan shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

FOR LOOP in C

Looping is process of performing some task repeatedly till certain condition is met loops are very best way to perform repeated task. looping are very efficient lets see what will be the approach, of writing your name 10 times, without using looping function

Uploaded by

ayan shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

for loop in C | Programmerdouts

programmerdouts.blogspot.com/2019/06/for-loop-in-c.html

for Loop
It works as while loop, But Syntax is very good as compare to other two loops.
Condition is checked before entering in the body of loop.
You can also call this as ,entry control loop.
Many programmer Prefer to go with is loop , because In this loop
initialization, condition, a nd increment of the variable is done in an single line,
Because of that You can Understand Concept of loop in better way.
Reading ability is very good as compare to other two loop.

Syntax

for(initializing ; condition ; increment)


{

//body of for loop.


}

Lets see the same program of printing number from 1 to 5 ,with for
loop.

#include<stdio.h> //header file


void main()
{
int i;

for(i = 1; i <= 5 ; i++)


{
// body of for loop.
printf("%d\n",i); //Printing the value of i , for every iteration.

}
}

1/2
Output:
1
2
3
4
5
Step by Step Explanation.
Valid values of i = 1,2,3,4,5 , for this program.
For i = 1,First Condition got checked and it was evaluated to true, so it print the value
of i. which is 1 and incremented it by 1.
Now value of has become 2,condition got check it evaluated to true and it printed the
value of i which is 2 and incremented it by 1.
Now i=3,Again with i =3,condition got check it evaluated to true and it printed the
value of i which is 3 and incremented it by 1.
Above step , will repeat until the condition gets evaluated to false.
In this example, for value of i = 6 ,loop will get terminate(stop) and control will go to
the next piece of code.
Control will not stay within the for loop, it will go to the next statements of the code.

Further Concepts

break keyword
continue keyword
difference between break and Continue keywords
Nested if-else statement
Practice Programs

Practice Programs

Programs Regarding If-else Statements


Program Regarding Nested If - statements
Programs Regarding loops

Further Topics

2/2

You might also like