LOOPS in C Language
By rswary
LOOPS:
To execute a set of instructions repeatedly until a particular condition is being satisfied.
Three types of looping statements are there
1) For Loop
2) While Loop
3) Do while Loop
For Loop:-
In for looping statement allows a number of lines represent until the condition is satisfied
Syntax:
for(initialize counter variable ; condition ; increment/decrement the counter variable)
{
Statement1;
...
Statement n;
}
Flow chart:
See the flowchart of for loop in figure1
Example program using for loop:
main()
{
int counter,a[10];
for(counter=0;counter<10;counter++)
{
printf(“Enter a[%d]=”,counter);
scanf(“%d\n”,a[counter]);
}
printf(“Array elements:”);
for(counter=0;counter<10;counter++)
printf(“%d”,a[counter]);
}
Explanation:
In above program array a length 10.It occupies 20bytes in memory.
Counter is normal integer variable. It is used to read and display the array values.
First FOR LOOP is used to read the array values.
Second FOR LOOP is used to display the array values. In this second FOR LOOP using one line. So, no need of brace brackets
WHILE LOOP:
In While looping statement allows a number of lines represent until the condition is satisfied
Syntax:
while( condition)
{
Statement1;
...
Statement n;
}
Flow chart:
See the figure2
Example program using while loop:
main()
{
int counter,a[10];
counter=0;
while(counter<10)
{
printf(“Enter a[%d]=”,counter);
scanf(“%d\n”,a[counter]);
counter+=1;
}
printf(“Array elements:”);
counter=0;
while(counter<10)
{
printf(“%d”,a[counter]);
counter+=1;
}
}
Explanation:
In above program array a length 10.It occupies 20bytes in memory.
Counter is normal integer variable. It is used to read and display the array values.
Before using counter variable to initialize counter. Then use it in WHILE LOOP.
First WHILE LOOP is used to read the array values.
Second WHILE LOOP is used to display the array values.
DO WHILE LOOP:
In DO WHILE LOOP first execute the statements then it checks the condition.
Syntax:
do
{
Statement1;
...
Statement n;
}while(condition);
Flow chart:
See the figure3
Example program using for loop:
main()
{
int counter;
counter=0;
do
{
printf(“%d”,counter);
}while(counter>0);
}
CONCLUTION:
In FOR LOOP:
No need to initialize variable before the LOOP
In WHILE LOOP:
To initialize the variable before the LOOP
Increment/decrement the variable within the LOOP
In DO WHILE LOOP:
Once it execute If the condition is TRUE/FALSE.
If u want to see my full website please visit below link
http://clanguagetutorials.blogspot.com/
Comments
Its nice keep it up........
that is good site for who r intersted in C language join it.
u shld hv put up tough examples too illustrating the same,like various patterns formed using for loop............
It is nice.But u r giving some examples only.Please................................. give more examples.
stuff is good.......but it could have been much more better....like more examples n little bit complicated promblems which is allready mentioned above
thanks to this site ok to ah keep it up mdmi kamtutu lungan,
it's nice page to study very well
ya it's nice and good.. study well
thanks man!!!!!!!!!! i had to take seminar for this and u guys gave a great explanation of loops even with examples..........THANKS!!!!
This site is very useful to learn the c language..
if anbody has to learn a c language very deeply please reffer this website
i m not fully satisfied from this site use more easy steps to learn while loops because all the next candidate will grow up
tnx 4 it......
its best site for for begners.......
ITS BEST SITE AND IT IS VERY USEFUL TO ALL STUDENTS BUT I REQUESTED TO U PLEASE GIVE EXAMPLE OF ALL TYPES OF LOOP THANKS MAM!!!!!!!!!!!!!!!!!!
ti's nice
wap to program to rectangle or circle with the help of looping.
its not easy for freasher
very nise .....
It is very useful to the students like me..Simply Superb!!
It is 2 easy
that is da information i needed about loop...gr8 job
mam plz give examples nd little bit explanation
These examples are so nice for the learning of c langue.
its nice.......website.
its nice n too easy but still we dont use dis type silly examples nowhere so wat i suggest is to explain wit both complicated and easy examples
iam not satasified in this example
thanks.
not enough given...
should be more elaborate..!!!
good site man
its very interesting but not easy 4 fresher...
its nice.......website.
example should be simple& clear
So late to knew about it,bcoz I have Xam day after 2morow
easy to understand
is not enough about loops
zabardast
im not satisfied for those examples ..
Nice information. Step wise step concept of looping are given.
under stand very easy
Hey I Need More Syntax Please Give me more.......... it's a nice working but i need more...
good way to learn thanx
Thanx alot 4 d info
.....nice i hope tamah po lhat ito ......thank u po kc nag post kau ng mga exmples pero i want more examples.....tnx.???
please give example that will take a number from the user
and print that number in the reverse order.
nice
very good
its very good side
this is very good for us
IT IS VERY NYC FOR US AND I LIKE IT
its good tostudy the looping
it is easy for us
its very nice to study loops
I LOVE THIS SITE(THANKYOU VERY MUCH)
plz can u tell me the purpose of loop...and then tell me how we use this .
dal ma ,a hs ans eisk bbwyxn syxji dfrin hyuin sdfcxfl
=means
can you identify this language
in english
why is loop
It's help the students.
Simple n best
I need help with one exercise. (Sorry for my English, I’m foreigner)
The program should count this equation: 2n/(1+2+…+n) using for.
n should be typed(?)(with scanf)
I’ve got:
S=0;
scanf(“%d”,&n);
for(int a=1;a(inequality sign)=n;++a){
S+=a;
2n/S=wynik;
printf("\t%d\n",wynik);
}
and all other necessary elements like ints, libraries and the rest and it doesn't work.
i like your method to convey the knowledge
Its really an easiest way for new learners of "C"....excellent site
very useful to learning.
very interesting
good. bet i want some more future examples of operation in the loop.
not easy for fresher
chawalllllllll..........
Thanks...Now I am completely ready for my computer exam.
very easy language to learn the looping concept in c
NICE THANKS :)
IN LANGUAGE C
WHAT THE CODE OF FOLLOWING DATA:
1
23
456
78910
SEND ANSWER TO E-MAIL ID - ali07.kvno3@gmail.com
it is very very nice website....................
![Microsoft Office Home & Student 2010 - 3PC/1User [Download]](http://ecx.images-amazon.com/images/I/41DDJftQoyL._SL75_.jpg)



monika 2 years ago
fabulous site inspiring to all who have c languge to study