Introduction to Looping in C

Discussion in 'C' started by lionaneesh, Jun 18, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India

    Looping



    While writing our C programs we might feel a need to execute similar or same set of instructions multiple times , for eg: Printing numbers from 1 to 100 on the screen , This task without the use of looping could be very tedious and make would make the code absolutely not redistributable and not readable. This problem was solved with the help of looping.

    Looping is a sequence of statements which are specified once and which can be carried out multiple times. During looping a set of instructions are executed until some conditions for termination of the loop is met.

    A loop basically consists of 2 parts:-
    1. The Control Statement
    2. The loop Body
    The Control Statement

    The control statement tests certain condition that then directs repeated of statements contained in the body of the loop.

    The loop body

    The loop body contains a set of instruction that will be executed until some condition for the termination of the loop is met.

    The Looping Process



    The looping process can be broken down in some steps:-

    1. Initialization and setting up of the counter (optional)
    2. Check if the conditions evaluate to true, Note: Some loops like the do-while loop executes the loop body first and then checks for conditions.
    3. Execute the loop body
    4. Increase the counter (optional)
    5. Start again from step 2

    Infinite Loops



    Infinite loops are a sequence of instructions that are executed endlessly. These loop occurs if there no terminating condition provided or a terminating condition that can never be met (like 1==2 etc.) or sometimes due to a run time error. In older systems infinite loops caused entire system to be irresponsive but in modern Operating Systems these loops can usually be terminated by the user.

    That’s all for this tutorial stay tuned for more
     
  2. prateekshaa

    prateekshaa New Member

    Joined:
    Jul 30, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    whats loop counter
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice