previous | contents | next

where the <v>'s indicate register real (floating point) or integer variables or constants which are substituted, <B> is a Boolean condition, and S is the statement or statements to be executed. In practice <v2>, <v3> and <v4> are often constants and can be positive or negative. Actually the Algol statement is even more general than this since <v2> can be replaced by a list of variables for <v1>, but we will not consider this case.

In terms of the for-loop the sum-of-integers problem, from Chapter 2, can be expressed in Algol as:

Note that in these cases the while B part is not used. This part is a further test for deciding whether to continue iterating and may replace the until part.

PROBLEM STATEMENT

The for-loop extended RTM is fairly complex and is classified as a K module, consisting of both a control and data part as shown in Figure FL-1.


Fig. FL-I. Module diagram of K(for loop) ERTM.

Design a K(for-loop) which assumes a macro (open subroutine) will be used for the do part. Use standard RTM's to specify the structure. Assume that if <v3> is positive the test for until-completion is (v1-v4) > 0 and for <v3> negative it is (v4-vl) >0. These two conditions can be expressed as: (vl-v4) * sign (v3) > 0.

 

SOLUTION

Figure FL-2 shows an RTM implementation of the K(for-loop). Memory for at

96

previous | contents | next