As in FORTRAN 77 any of the following forms of the IF statement may be used:
IF log_exp command ! command = any MIDAS command
! with at most 4 params.
IF log_exp THEN ! xyz = any logical expression
...
ELSEIF log_exp THEN ! uvw = any logical expression
...
ELSE
...
ENDIF
IF log_exp THENIF blocks may be nested up to 8 levels deep in a procedure.
...
ENDIF
arg1 op arg2where arg1, arg2 are either names of keywords (this includes also the names P1, ..., P8) or constants, and op may be any of .EQ., .NE., .GT., .GE., .LT. or .LE. (with the same meaning as in FORTRAN 77). As with symbol substitution, specify single elements of an array and substrings via, e.g., OUTPUTI(7) and IN_B(2:15).
WRITE/KEYWORD INPUTC beerThen,
WRITE/KEYWORD OUTPUTC wine
WRITE/KEYWORD INPUTR/R/1/3 1.,2.,3.
INPUTC .EQ. "beer" is TRUEIn string comparisons upper and lower case characters are not distinguished in order to guarantee case insensitivity.
INPUTC .EQ. "BEER" is also TRUE
INPUTC .EQ. OUTPUTC is FALSE
INPUTC(2:2) .EQ. OUTPUTC(4:4) is TRUE
INPUTR(2) .GT. 5.4 is FALSE
!+Entering @@ exa13a 1 as well as @@ exa13a 001 will give the expected output message P1 = 1 since the line IF P1 .EQ. 1 THEN has been converted in the first pass by the Monitor to
! Example 13a, MIDAS procedure exa13a.prg
!+
DEFINE/PARAM P1 ? N "Enter number: "
DEFINE/MAXPAR 1 ! only one parameter expected
IF P1 .EQ. 1 THEN
WRITE/OUT P1 = 1
ELSE
WRITE/OUT P1 is not = 1
ENDIF
!+Entering @@ exa13b 1 will return the error message invalid IF statement... and abort. Why?
! Example 13b, MIDAS procedure exa13b.prg
!+
DEFINE/PARAM P1 ? N "Enter number: "
DEFINE/MAXPAR 1 ! only one parameter expected
IF P1 .EQ. 1 THEN
WRITE/OUT P1 = 1
ELSE
WRITE/OUT P1 is not = 1
ENDIF
!+Now, entering @@ exa13c 1 will work and yield P1 = 1 but @@ exa13c 001 will output P1 is not = 1 since the string "001" is not equal to "1".
! Example 13c, MIDAS procedure exa13c.prg
!+
DEFINE/PARAM P1 ? N "Enter number: "
DEFINE/MAXPAR 1 ! only one parameter expected
IF P1 .EQ. "1" THEN
WRITE/OUT P1 = 1
ELSE
WRITE/OUT P1 is not = 1
ENDIF
!+However, if we also want to check the limits of the given number we have to use the DEFINE/PARAMETER command again, because testing "+" against a numerical interval would lead to an error:
! Example 14a, MIDAS procedure exa14a.prg
!+
DEFINE/PARAM P6 + NUMBER "Enter first input number: "
IF P6(1:1) .EQ. "+" THEN
WRITE/KEYWORD INPUTC NONE ! no P6 entered, set INPUTC accordingly
ELSE
WRITE/KEYWORD INPUTI/I/7/1 P6! store contents of P6 in INPUTI(7)
WRITE/KEYWORD INPUTC YES !indicate, that INPUTI holds a valid number
ENDIF
!+Since, in the ELSE branch we know that parameter P6 is given, the default value "+" itself is never tested against the interval [22,1024].
! Example 14b, MIDAS procedure exa14b.prg
!+
DEFINE/PARAM P6 + NUMBER "Enter first input number: "
IF P6(1:1) .EQ. "+" THEN
WRITE/KEYWORD INPUTC NONE ! no P6 entered, set INPUTC accordingly
ELSE
DEFINE/PARAM P6 + NUMBER "Enter first input number: " 22,1024
WRITE/KEYWORD INPUTI/I/7/1 P6! store contents of P6 in INPUTI(7)
WRITE/KEYWORD INPUTC YES !indicate, that INPUTI holds a valid number
ENDIF
!+Then, @@ exa15 ANALOG will execute the command RUN ANALO and @@ exa15 digital or @@ exa15 di will run the program digi.exe.
! Example 15, MIDAS procedure exa15.prg
!+
DEFINE/PARAMETER P1 ? C "Enter method: "
DEFINE/MAXPAR 1 ! only one parameter expected
!
! Use the first 2 characters of parameter P1 to distinguish the methods BRANCH P1(1:2) AN,DI,HY ANALOG,DIGIT,HYBRID
!
! fall through if no match ...
WRITE/OUT Invalid option - please try again
RETURN
!
ANALOG:
RUN ANALO
RETURN
!
DIGIT:
RUN DIGI
RETURN
!
HYBRID:
RUN HYBRI