rswary profile image

LOOPS in C Language

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

 

 

See all 3 photos
See all 3 photos
See all 3 photos

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/

 

 

 Last updated on October 6, 2009

Useful {23}Funny {13}Awesome {11}Beautiful {12}Interesting {12}

Comments 88 comments

monika 4 years ago

fabulous site inspiring to all who have c languge to study

Kiran Kilari 4 years ago

Its nice keep it up........

Shaheer ABBAS 4 years ago

that is good site for who r intersted in C language join it.

priyanka 4 years ago

u shld hv put up tough examples too illustrating the same,like various patterns formed using for loop............

Meena 3 years ago

It is nice.But u r giving some examples only.Please................................. give more examples.

arthi 3 years ago

stuff is good.......but it could have been much more better....like more examples n little bit complicated promblems which is allready mentioned above

carlits08 3 years ago

thanks to this site ok to ah keep it up mdmi kamtutu lungan,

shaffaq jawed 3 years ago

it's nice page to study very well

Ahamed 3 years ago

ya it's nice and good.. study well

vishnu shanker 3 years ago

thanks man!!!!!!!!!! i had to take seminar for this and u guys gave a great explanation of loops even with examples..........THANKS!!!!

syed 3 years ago

This site is very useful to learn the c language..

if anbody has to learn a c language very deeply please reffer this website

pintu 3 years ago

i m not fully satisfied from this site use more easy steps to learn while loops because all the next candidate will grow up

aditi 3 years ago

tnx 4 it......

Shafiq ur rehman 3 years ago

its best site for for begners.......

gitanjali  3 years ago

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!!!!!!!!!!!!!!!!!!

bobby 3 years ago

ti's nice

sandeep gehlot 3 years ago

wap to program to rectangle or circle with the help of looping.

nishi 3 years ago

its not easy for freasher

Niwash kumar  3 years ago

very nise .....

swathi 3 years ago

It is very useful to the students like me..Simply Superb!!

yogesh 3 years ago

It is 2 easy

Jawad khan 3 years ago

that is da information i needed about loop...gr8 job

nimra 3 years ago

mam plz give examples nd little bit explanation

iqbal Qureshi  3 years ago

These examples are so nice for the learning of c langue.

UMAIR KHAN 3 years ago

its nice.......website.

anusha chowdary 3 years ago

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

naveen 3 years ago

iam not satasified in this example

vijay 3 years ago

thanks.

himanshu 3 years ago

not enough given...

should be more elaborate..!!!

manu 3 years ago

good site man

ashum 3 years ago

its very interesting but not easy 4 fresher...

hadi hassan 3 years ago

its nice.......website.

archana sharma 3 years ago

example should be simple& clear

GRIEGTHE 3 years ago

So late to knew about it,bcoz I have Xam day after 2morow

kavitha 3 years ago

easy to understand

zameel 3 years ago

is not enough about loops

waseem nawaz 3 years ago

zabardast

hmmmm  3 years ago

im not satisfied for those examples ..

Sedona canyon 3 years ago

Nice information. Step wise step concept of looping are given.

mohamed 3 years ago

under stand very easy

Dushyant Agheda 3 years ago

Hey I Need More Syntax Please Give me more.......... it's a nice working but i need more...

tarun 2 years ago

good way to learn thanx

Anitha 2 years ago

Thanx alot 4 d info

jomhelmar orioke 2 years ago

.....nice i hope tamah po lhat ito ......thank u po kc nag post kau ng mga exmples pero i want more examples.....tnx.???

fatema 2 years ago

please give example that will take a number from the user

and print that number in the reverse order.

ravi lohar 2 years ago

nice

Mohammad Danish 2 years ago

Nyc one bro!

people interested can also check this out

http://thetechnofreaks.com/2011/09/04/531/

ashu 2 years ago

very good

monika 2 years ago

its very good side

kotesh 2 years ago

this is very good for us

PARAS COOL 2 years ago

IT IS VERY NYC FOR US AND I LIKE IT

neha katoch 2 years ago

its good tostudy the looping

Tara mehta 2 years ago

it is easy for us

nadia 2 years ago

its very nice to study loops

DEEGU 2 years ago

I LOVE THIS SITE(THANKYOU VERY MUCH)

sadia malik 2 years ago

plz can u tell me the purpose of loop...and then tell me how we use this .

dh 2 years ago

dal ma ,a hs ans eisk bbwyxn syxji dfrin hyuin sdfcxfl

=means

can you identify this language

in english

pankaj 2 years ago

why is loop

kamal kishor 2 years ago

It's help the students.

Suman dhamala 2 years ago

Simple n best

Monika 2 years ago

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.

Ehsan 2 years ago

i like your method to convey the knowledge

honey 2 years ago

Its really an easiest way for new learners of "C"....excellent site

R.Manikandan 2 years ago

very useful to learning.

fe 2 years ago

very interesting

jai 2 years ago

good. bet i want some more future examples of operation in the loop.

hadia 2 years ago

not easy for fresher

Naina 2 years ago

chawalllllllll..........

Tanuj Nath 2 years ago

Thanks...Now I am completely ready for my computer exam.

priyavrat 2 years ago

very easy language to learn the looping concept in c

ALI AFRIDI 2 years ago

NICE THANKS :)

eliyash 2 years ago

IN LANGUAGE C

WHAT THE CODE OF FOLLOWING DATA:

1

23

456

78910

SEND ANSWER TO E-MAIL ID - ali07.kvno3@gmail.com

md.sadre alam 2 years ago

it is very very nice website....................

Warda Ahmed 2 years ago

nyc ha

tell me 1 thing ASCII TABLE 3 charactrs ko b cover karta ha or 4 ko b plxxxx ans me em waitnig

on this id

princess_warda_143@hotmail.com

trnapatil986@gmail.com 2 years ago

that are good site for programming. thanks to given these site

sai rama krishna 2 years ago

Can you send me some miscnellous exercises on the loop

programs?

gopi chodvadiya 22 months ago

help full

maryam 22 months ago

programing make a life intresting

kunu 20 months ago

sir can we apply the loop in that condition where the value will be given as infinite

rabi 20 months ago

easy study of c-language of loop

Naveen Batra 19 months ago

I am satisfied in this example. Its good.

dharmraj 18 months ago

not satisfied

krishan kant azad 17 months ago

pls you give me nots in for loop

thankyou very much

santoshbvn 16 months ago

good explanation

anagha 13 months ago

quite niceeee

jay 13 months ago

what is meaning of for(;;) loop in c language without any statement inside

1111122222222222222222233333333333333333333344444444444444444444 11 months ago

333333333333333333333333333333333333333333333333333333333

saranya 10 months ago

nice but need to explain more

    Sign in or sign up and post using a HubPages account.

    8192 characters left.
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your Hubs or other sites.


    Microsoft Word 2013 Key Card Non-Commercial (1PC/1User)
    Microsoft Word 2013 Key Card Non-Commercial (1PC/1User)
    Amazon Price: $49.99
    List Price: $79.99
    Click to Rate This Article
    Please wait working