HP 3000 Manuals

REPEAT [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

REPEAT 

The REPEAT and UNTIL statements define a loop that repeats until the
boolean expression in the UNTIL statement is TRUE (nonzero).

Syntax 

REPEAT [stmt] .  .  .  UNTIL boolean_expr 

Parameters 

stmt             Program line that is executed until boolean_expr 
                 evaluates to TRUE. These statements constitute the loop
                 body.  The loop body is always executed once prior to
                 the evaluation of boolean_expr.

boolean_expr     Considered FALSE if it evaluates to zero; TRUE
                 otherwise.

Examples 

     10 Nums_read=0
     20 REPEAT                          !Begin loop
     30   READ Number
     40   Nums_read=Nums_read+1
     50 UNTIL Number                    !End loop when Number<>0
     60 PRINT Nums_read," numbers read"
     99 END

REPEAT constructs can be nested.

     100 REPEAT                   !Begin outer loop
     110   READ Number1
     120   REPEAT                 !Begin inner loop
     130     READ Number2
     140   UNTIL Number1-Number2  !End inner loop
     150 UNTIL Number1+Number2    !End outer loop
     160 PRINT Number1,Number2
     999 END

Entering a REPEAT loop in the middle of the loop is considered to be a
bad programming practice, and is not recommended.  However, calling a
local subroutine using GOSUB or calling an external subroutine using CALL
from within a REPEAT construct can be useful.

     100 REPEAT                         !Begin loop
     110   READ N1,N2
     120   IF (N1 MOD 2) THEN GOSUB 200 !If N1 is odd, exit the loop
     125   PRINT N1
     130 UNTIL N2                       !End loop
     140 STOP
     200 N1=2*N1
     210 RETURN                         !Return to inside of loop
     999 END



MPE/iX 5.0 Documentation