Flag This Hub

LOOPS in C Language

By


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

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

monika 2 years ago

fabulous site inspiring to all who have c languge to study

Kiran Kilari 2 years ago

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

Shaheer ABBAS 2 years ago

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

priyanka 2 years ago

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

Meena 21 months ago

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

arthi 20 months 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 20 months ago

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

shaffaq jawed 19 months ago

it's nice page to study very well

Ahamed 19 months ago

ya it's nice and good.. study well

vishnu shanker 18 months ago

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

syed 18 months 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 18 months 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 18 months ago

tnx 4 it......

Shafiq ur rehman 18 months ago

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

gitanjali  18 months 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 17 months ago

ti's nice

sandeep gehlot 17 months ago

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

nishi 17 months ago

its not easy for freasher

Niwash kumar  17 months ago

very nise .....

swathi 17 months ago

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

yogesh 17 months ago

It is 2 easy

Jawad khan 17 months ago

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

nimra 17 months ago

mam plz give examples nd little bit explanation

iqbal Qureshi  16 months ago

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

UMAIR KHAN 16 months ago

its nice.......website.

anusha chowdary 16 months 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 15 months ago

iam not satasified in this example

vijay 15 months ago

thanks.

himanshu 15 months ago

not enough given...

should be more elaborate..!!!

manu 14 months ago

good site man

ashum 14 months ago

its very interesting but not easy 4 fresher...

hadi hassan 14 months ago

its nice.......website.

archana sharma 14 months ago

example should be simple& clear

GRIEGTHE 13 months ago

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

kavitha 13 months ago

easy to understand

zameel 12 months ago

is not enough about loops

waseem nawaz 12 months ago

zabardast

hmmmm  11 months ago

im not satisfied for those examples ..

Sedona canyon 10 months ago

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

mohamed 9 months ago

under stand very easy

Dushyant Agheda 9 months ago

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

tarun 9 months ago

good way to learn thanx

Anitha 9 months ago

Thanx alot 4 d info

jomhelmar orioke 9 months 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 8 months ago

please give example that will take a number from the user

and print that number in the reverse order.

ravi lohar 8 months ago

nice

Mohammad Danish 8 months ago

Nyc one bro!

people interested can also check this out

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

ashu 8 months ago

very good

monika 8 months ago

its very good side

kotesh 8 months ago

this is very good for us

PARAS COOL 8 months ago

IT IS VERY NYC FOR US AND I LIKE IT

neha katoch 8 months ago

its good tostudy the looping

Tara mehta 8 months ago

it is easy for us

nadia 8 months ago

its very nice to study loops

DEEGU 7 months ago

I LOVE THIS SITE(THANKYOU VERY MUCH)

sadia malik 6 months ago

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

dh 6 months ago

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

=means

can you identify this language

in english

pankaj 5 months ago

why is loop

kamal kishor 5 months ago

It's help the students.

Suman dhamala 5 months ago

Simple n best

Monika 5 months 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 5 months ago

i like your method to convey the knowledge

honey 4 months ago

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

R.Manikandan 4 months ago

very useful to learning.

fe 4 months ago

very interesting

jai 4 months ago

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

hadia 3 months ago

not easy for fresher

Naina 2 months ago

chawalllllllll..........

Tanuj Nath 2 months ago

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

priyavrat 2 months ago

very easy language to learn the looping concept in c

ALI AFRIDI 6 weeks ago

NICE THANKS :)

eliyash 6 weeks 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 3 weeks ago

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

Submit a Comment
Members and Guests

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



    Microsoft Office Home & Student 2010 - 3PC/1User [Download]
    Amazon Price: $115.00
    List Price: $149.99
    QuickBooks Pro 2012
    Amazon Price: $131.89
    List Price: $229.99
    Microsoft Office Home & Business 2010 - 2PC/1User (Disc Version)
    Amazon Price: Too low to display
    List Price: $279.99
    The Print Shop v.23 (JC)
    Amazon Price: $4.64
    List Price: $9.99
    Like this Hub?
    Please wait working