Oct 20, 2018, 12:13 AM

News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!


Loops in c languages

Started by jayanthi mandhalapu, Jul 29, 2009, 10:06 PM

previous topic - next topic
Go Down

jayanthi mandhalapu

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.


Be Happy And Always Remain So

june

hi
how are you ?
i have project in loop but i dont know how to solve it ? :'(
can you help me ,plz?

s.jegan

plz help me
what program to make a this output?
1
23
456
78910

pradeep prem

there are more loops in this website

thanks for share

chin_x

Thanks, in advance, for any info. :-*









ไฮไลท์บอล คู่เด็ดเมื่อคืน ทุกคู่ ทุกแมต ได้ที่นี่ ไฮไลท์ฟุตบอลเมื่อคืน

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:
Verification:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens | GinGly :: SMS Backup | Acumen :: Discussion Board | AshokPillar :: Hosting | CineBuzz :: Latest Cinema News | My Kids Diary :: Capture your kids magical moment
Copyright 2005 - 2017 :: IT Acumens :: All Rights Reserved.
ITAcumens Forum with 2 lakhs post running for 10 years - Powered by HostGator Dedicated Server