FOR LOOP in C
FOR LOOP in C
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
Lets see the same program of printing number from 1 to 5 ,with for
loop.
}
}
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
Further Topics
2/2