Home | Hindi | Kabir | Poetry | Workshop | BoloKids | Writers | Contribute | Search | Contact | Share This Page!                      Shop Online

  News
Channels
In Focus

Analysis  
Bolography  
Cartoons
Environment   
Opinion 

Columns
 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
Jagoji
Literary Shelf 
Love Letters  
Memoirs
Musings
Ramblings
Stories
Travelogues

Computing
  General Articles
 
CC++ 
  Flash 
  Internet Security 
 
Java 
 
Linux     
  Networking  

Computing | CC++   
Decision Making And Looping

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.

– Sachin Mehta
February 8, 2001

C/C ++        
Managing Input-Output Operations
     
Managing Output Operations
    
Decision Making And Branching
     
Decision Making and Branching (if statement)
     
Decision Making and Looping
    
The Do Statement
   
Arrays
    
Arrays - Multi-Dimensional
    
Handling of Character Strings
    
Handling of Character Strings - 2  
User Defined Functions   
   User Defined Functions...contd    
Handling of Functions  

Computing
Flash | Internet Security 
Java | Linux | Networking  

General Articles  

Top | Previous | Next   
 


 

Recommend This Page!

Analysis | Architecture | Astrology | Ayurveda | Book Reviews | Buddhism | Cartoons | Cinema | Computing | Culture | Dances
Environment | Fables | Family Matters | Festivals | Hinduism | Health | History | Home Remedies | Humor | Individuality | Jagoji
Literary Shelf | Memoirs | Musings | Opinion | Parenting | Perspective | Photo Essays | Places | Ramblings
Random Thoughts | Recipes | Sikhism | Society | Spirituality | Stories | Teens | Travelogues | Vastu | Vithika | Women

Home | Hindi | Bolography | BoloKids | Kabir | Poetry | Quotes | Workshop | Writers | Contribute | Search | Contact


Boloji.com is owned and managed by Boloji Media Inc

Privacy Policy | Disclaimer
No part of this Internet site may be reproduced without prior written permission of the copyright holder.