Algorithms



Semantics (Meaning) of Loops

Consider the statements:

1. repeat until x > 99

2.    x <- x + 1

Now Unwind the loop:

1. x <- x + 1

2. if x < 99 then

3.    x <- x + 1

4.    if x < 99 then

5.        x <- x + 1

6.        if x < 99 then
                :
                :

In general this unravelling results in an infinite representation, not a proper one.

Iteration is where potentially unbounded computations can arise.

How could you limit the expansion to a finite number of repetitions?


Always make sure a loop has an "escape" route.

[Prev][TOC]


CS1104 Main Page
Last Updated 01/05/2000
© L.Heath, 2000