i2tutorials

Iteration and Repetitive Execution of Loops

Iteration and Repetitive Execution of Loops

 

Selection and iteration statements are the basic tools of designing a logical process.

 

Concept of a Loop

 

 

loop iteration

 

 

Unbounded iteration / Unbounded Loop:

 

When one doesn’t know, how many iterations may be required ahead of time, such cases require unbounded loops.

Two types of such loops are:

These loops are also known as indeterminate or indefinite loops.

 

Bounded iteration / Bounded loop:

 

When we know, how many times we need to loop; such cases are called bounded loops.

 

Pre-test and Post-test Loops:

 

Pre-test Loop:

 

The condition is checked before we start and at the beginning of each iteration. If the test condition is true, we run the code; if the test condition is wrong, we terminate the loop. The statements associated with this type of construct may not be executed even once.

 

 

Post-test Loop:

 

The condition is tested ad if the expression is true, the loop repeats, if the expression (condition) is false, the loop terminates. But, before the condition is tested for the first time, the actions are executed at least once. The statements associated with this construct may be executed at least once.

 

 

Exit mobile version