1. Home
  2. ENDIF directive

ENDIF directive

Indicates the end of a block-if control structure.

No options or parameters

Description

A block-if structure consists of one or more alternative sets of statements. The first of these is introduced by an IF statement. There may then be further sets introduced by ELSIF statements. Then you can have a final set introduced by an ELSE statement, and the whole structure is terminated by an ENDIF statement. Full details are given in the description of the IF directive.

Options: none.

Parameters: none.

See also

Directives: IF, ELSIF, ELSE, EXIT.

Commands for: Program control.

Example

" Example PROC-1: Defining a procedure"

PROCEDURE 'SQUARERT'
   " Define the options & parameters of the procedure "
   OPTION NAME='PRINT','TRACE'; MODE=t; DEFAULT='no'
   PARAMETER NAME='X','ROOTX'; MODE=p
   " Check that the option settings are valid and set scalars
     Sprint and Strace to indicate whether they are set to yes "
   SCALAR Sprint,Strace
   FOR Setting=PRINT,TRACE; Sset=Sprint,Strace
      IF Setting .EQS. 'yes'
         CALCULATE Sset = 1
      ELSIF Setting .EQS. 'no' 
         CALCULATE Sset = 0
      ELSE 
         EXIT [CONTROLSTRUCTURE=procedure] 
      ENDIF
   ENDFOR
   " Check for invalid setting of parameter X ( i.e. < 0 ) "
   IF X < 0 
      PRINT 'X < 0 :  square root cannot be calculated'
   ELSE
   " Calculate convergence limit & initialize "
      CALCULATE Clim = X/10000  & ROOTX = X
   " Loop until convergence "
      FOR [NTIMES=20]
         CALCULATE Previous = ROOTX
         & ROOTX = (X/Previous + Previous)/2
         IF Strace 
            PRINT [IPRINT=*] ROOTX
         ENDIF
         EXIT ABS(Previous-ROOTX) < Clim
      ENDFOR
      IF Sprint 
         PRINT [IPRINT=*] 'square root of ',X,' is ',ROOTX;\
            JUSTIFICATION=left
      ENDIF
   ENDIF
ENDPROCEDURE

" Use the procedure"
SCALAR Rx 
SQUARERT X=48; ROOTX=Rx 
PRINT Rx

" Use it and set the option"
SQUARERT [PRINT=yes] X=48; ROOTX=Rx 
SQUARERT [PRINT=yes; TRACE=yes] 81; ROOTX=Rx
Updated on March 8, 2019

Was this article helpful?