Decision Making And Looping

In looping, a sequence of statements are executed until some condition is satisfied which is defined for termination of the loop.

A program loop consists of two segments,

  • Body of the loop
  • 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:

  • Setting and initialization of a counter.
  • Execution of the statements in the loop.
  • Test for a specified condition for execution of the loop.
  • Incrementing the counter.

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

  • Switch Case
  • goto Statement
  • while loop
  • do-while loop
  • for loop
  • Nesting of loops
  • Flow breaking statement: break and continue

The reference site for this content is http://www.boloji.com/computing/ccplus/cc006.htm

Back