Saturday, October 8, 2011

Looping concept

The program that we have developed so far used either a sequential or a decision control instruction.
The versatility of the computer lies in its ability to perform a set of instructions repeatedly. This involves repeating some portion of the program either a specified number of times or until a particular condition is being satisfied. This repetitive operation is done through a loop control instruction.
Loops can be created to executed a block of code for a fixed number of times. Alternatively, loops can be created to repetitively execute a block of code until a Boolean condition changes state.
For instance, the loop may continue until a condition changes from false to true, or from true to false. In this case, the block o code being executed must update the condition being tested in order for the loop to terminate at some point. If the test condition is not modified somehow within the loop, the loop will never terminate. This created a programming bug known as an infinite loop.
There are three method by way to which we can repeat a part of a program. They are:
  1. Using a for statement
  2. using a while statement
  3. Using a do-while statement

No comments:

Post a Comment