Contents - Index


REPEAT - UNTIL

 

REPEAT - UNTIL statements can only be used in internal functions or procedures.  REPEAT - UNTIL statements provide logical operations in the same manner as in  IF - THEN - ELSE and CASE statements, but they are often somewhat more  convenient, especially for looping operations.  The REPEAT - UNTIL statements are written in the same manner as in Pascal.  Note the REPEAT - UNTIL construct cannot be used in the Main program or in Modules and Subprograms.  Here is a small function which uses the REPEAT - UNTIL statements.

 

     FUNCTION SUMINV(X)

         SUMX:=0;  i:=0

         REPEAT

             i:=i+1

             SUMX:= SUMX+1/X^i

        UNTIL (i>10)

        SUMINV:=SUMX

     END

 

Note that Duplicate loops should are not appropriate for use in internal functions or procedures.  The Duplicate statement literally duplicates the equation, substituting the duplicate index as appropriate during the compiling stage so it is then not possible to pass the lower or upper bound of the Duplicate loop as a parameter.  However, EES internally changes Duplicate loops into Repeat-Until blocks during compilation.  As a result, the following function:

 

             function SumIt(N, X[1..N])

                 Sum=0

                 Duplicate i=1,N

                    Sum=Sum+X[i]

                 end

                 SumIt=Sum

           end

 

is internally represented as:

 

            function SumIt(N, X[1..N])

                Sum=0

                i=0

                repeat

                   i=i+1

                   Sum=Sum+X[i]

                until (i>=N)

                SumIt=Sum

            end