Decision Making And Looping by Sachin Mehta SignUp
Boloji.com
Boloji
Home Kabir Poetry Blogs BoloKids Writers Contribute Search Contact Site Map Advertise RSS Login Register
Boloji
Channels

In Focus

Analysis
Cartoons
Education
Environment
Going Inner
Opinion
Photo Essays

Columns

A Bystander's Diary
Business
My Word
PlainSpeak
Random Thoughts

Our Heritage

Architecture
Astrology
Ayurveda
Buddhism
Cinema
Culture
Dances
Festivals
Hinduism
History
People
Places
Sikhism
Spirituality
Vastu
Vithika

Society & Lifestyle

Family Matters
Health
Parenting
Perspective
Recipes
Society
Teens
Women

Creative Writings

Book Reviews
Ghalib's Corner
Humor
Individuality
Literary Shelf
Love Letters
Memoirs
Musings
Quotes
Ramblings
Stories
Travelogues
Workshop

Computing

CC++
Computing Articles
Flash
Internet Security
Java
Linux
Networking
CC++ Share This Page
Decision Making And Looping
by Sachin Mehta Bookmark and Share
 

In looping, a sequence of statements are executed until some condition is satisfied which is placed for termination of the loop. A program loop consists of two segments, one is the body of the loop and the other known as the control statement. The control is tested always for execution of the body of the loop. Depending on the position of the control statement in the loop, a control may be classified as the entry-controlled loop or as the exit-controlled loop. In the entry-controlled loop, first the conditions are tested and if satisfied then only  body of loop is executed. In the exit-controlled, the test is made at the end of the body, so the body is executed unconditionally first time.

A looping process, in general, would involve the following four steps:
  1. Setting and initialization of a counter.
  2. Execution of the statements in the loop.
  3. Test for a specified condition for execution of the loop.
  4. Incrementing the counter.

The C language provides for three loop constructs for performing loop operations. They are:

  1. The while statement.
  2. The do statement.
  3. The for statement.

Loops find application in almost all C/C++ programs that you're likely to encounter. So I'll deal this topic in detail. So it's spread over two articles.

The while Statement

This is one of the most simplest looping structure. The basic format of the while statement is

while (test condition)
{
   body of the loop

The while is an entry-controlled loop statement. The test condition is evaluated and only if the condition is true the body is executed. After execution of the body, the test-condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the test-condition finally becomes false and the control is transferred  out of the loop. On exit, the program continues with the statement immediately after the body of the loop. If the body contains only one statement its not necessary to put the braces, but placing them is a good programming practice.

Example:
........
.......
x = 10;                    -------------   Initialization
while (x < 16)          -------------   Test condition
{
  printf("%d",x);        -------------   body of the loop
  x = x+1;
}   
........

The above example shows a simple position where the test condition is evaluated first and since the test is satisfied the body is executed. This will continue exactly six times printing out 10 to 15. Finally when x becomes 16 then test fails & so the loop ends. The program continues with the statements after the loop.

The next article will deal with do-while and for loops. So do join in next time.

8-Feb-2001
More by :  Sachin Mehta
 
Views: 3475
Share This Page
Post a Comment
Bookmark and Share
Name*
Email ID*  (will not be published)
Comment
Verification Code*
F5M25
Please fill the above code for verification.

    

 
 
Top | CC++



Solitude and other poems by Rajender Krishan
 


    A Bystander's Diary     Analysis     Architecture     Astrology     Ayurveda     Book Reviews
    Buddhism     Business     Cartoons     CC++     Cinema     Computing Articles
    Culture     Dances     Education     Environment     Family Matters     Festivals
    Flash     Ghalib's Corner     Going Inner     Health     Hinduism     History
    Humor     Individuality     Internet Security     Java     Linux     Literary Shelf
    Love Letters     Memoirs     Musings     My Word     Networking     Opinion
    Parenting     People     Perspective     Photo Essays     Places     PlainSpeak
    Quotes     Ramblings     Random Thoughts     Recipes     Sikhism     Society
    Spirituality     Stories     Teens     Travelogues     Vastu     Vithika
    Women     Workshop
RSS Feed RSS Feed Home | Privacy Policy | Disclaimer | Site Map
No part of this Internet site may be reproduced without prior written permission of the copyright holder.
Developed and Programmed by ekant solutions