Hello friends
Today we will discuss about loops in C programming Language.
Loops are repeatedly executed for a certain number of times.C Programming Language supports three types of loop control statements for loop,while loop and do_while loop.
For loop allows to execute a set of instructions until a certain condition is satisfied.Conditions may be predefined.It comprises three actions or parameters.These three actions are initialisation, test_condition and Re-evaluation which are separated by semicolons.
Syntax :
for(initialisation,test_condition,re-evaluation)
{}
The initialization sets to an initial value.This statement is executed only once.
The test_condition is a relational expression that determines the number of iterations.
The re-evaluation decides how to make changes in the loop by increment or decrement operations.
We can write for loop in different ways:
1.Infinite loop
for(;;)
It goes infinite. It has no arguments/parameters.
for(a=0;a<=20;)
It also goes infinite because 'a' is neither incremented nor decremented.
2.Finite loop
for(a=0;a<=20;a++)
It display values from 0 to 20.
for(a=20;a>=0;a++)
It display values from 20 to 0.
A program to find square root.
No comments:
Post a Comment