My Anna

Indias Biggest Engineering Education Community Enriching Students Minds with Latest Placement Papers, Study Materials, Fresher Jobs and Free E Books

A Unit of Aim Clear Technologies Ltd.
Search Study Materials, Jobs, Placement Papers, Interview Tips, Training Videos & More

Advertise with us

Who is online



Post new topic Reply to topic  [ 1 post ] 

neha
Marketing Executive
Marketing Executive
User avatar

Joined:
Mon Aug 24, 2009 10:57 pm
Beans: 767
In Bank: 10965
College: IET
Degree: B.E
Position: Teacher
 
#2
Tue Sep 15, 2009 5:09 pm
Post subject: Loops In C Language Post
Most real programs contain some construct that loops within the program, performing repetitive actions on a stream of data or a region of memory. There are several ways to loop in C. Two of the most common are the while loop:

while (expression)
{
...block of statements to execute...
}

and the for loop:

for (expression_1; expression_2; expression_3)
{
...block of statements to execute...
}

The while loop continues to loop until the conditional expression becomes false. The condition is tested upon entering the loop. Any logical construction (see below for a list) can be used in this context.

The for loop is a special case, and is equivalent to the following while loop:

expression_1;

while (expression_2)
{
...block of statements...

expression_3;
}

For instance, the following structure is often encountered:

i = initial_i;

while (i <= i_max)
{
...block of statements...

i = i + i_increment;
}

This structure may be rewritten in the easier syntax of the for loop as:

for (i = initial_i; i <= i_max; i = i + i_increment)
{
...block of statements...
}

Infinite loops are possible (e.g. for(;;)), but not too good for your computer budget! C permits you to write an infinite loop, and provides the break statement to ``breakout '' of the loop. For example, consider the following (admittedly not-so-clean) re-write of the previous loop:

angle_degree = 0;

for ( ; ; )
{
...block of statements...

angle_degree = angle_degree + 10;
if (angle_degree == 360) break;
}

The conditional if simply asks whether angle_degree is equal to 360 or not; if yes, the loop is stopped.

Profile E-mail
Offline

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 
Bookmark & Share

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB Group.

phpBB SEO