If

If is used to perform tests in a script.

Syntax

  If NUMERIC_EXPRESSION
    list_of_instructions_if
  Endif

  If NUMERIC_EXPRESSION
    list_of_instructions_if
  Else
    list_of_instructions_else
  Endif

  If NUMERIC_EXPRESSION
    list_of_instructions_if
  Elsif NUMERIC_EXPRESSION
    list_of_instructions_elsif
  Endif

  If NUMERIC_EXPRESSION
    list_of_instructions_if
  Elsif NUMERIC_EXPRESSION
    list_of_instructions_elsif
  Else
    list_of_instructions_else
  Endif

Examples

# First example
  If I=1
    # Line executed if I=1
  Else
    # Line executed if I is not equal to 1
  Endif

# Second example
  If find(CHOICE,"YES","SURELY","CERTAINLY","PERHAPS","MAYBE","POSSIBLY")
    # If CHOICE is in the values listed, find returns the rank in the list and this branch will be executed
  Else
    # If CHOICE is out of the list, find returns 0 and this branch will be executed
  Endif

# More complex alternative
If I=1
  # Line executed if I=1
Elsif I=2 or I=1
  # Line executed only if I=2 (the first branch has been executed if I=1)
Elsif func STRANGE(I)=3
  # Line executed if the condition is fulfilled. Take care, I might have been modified by Funprog STRANGE
Elsif I=1 or I=3
  # Line executed if I was not equal to 1 and 2, if the condition STRANGE(I)=3 was false,
  # buf if I is equal to 1 or 3 after execution of STRANGE Subprog
Else
  # Line executed in all other cases
Endif

Description and comments

See also

Else, Elsif, Endif.