IF

Function

Executes commands depending on the value of a condition.

Syntax

IF logical_expression

IF commands have the following structure:

IF logical_expression
sqr_commands...
[ELSE
sqr_commands...]
END-IF

Arguments

logical_expression

Any valid logical expression. See LET for a description of logical expressions.

Operators

See Bit-Wise Operators for information on the bit-wise operators supported by IF.

Description

The expression is evaluated as a logical TRUE or FALSE. A value or expression that evaluates to nonzero is TRUE.

Each IF must have a matching END-IF.

IF commands can be nested.

Comparing a date variable or column with a string, results in a date comparison (chronological, not a byte by byte comparison as is done for strings). The string must be in the proper format as follows:

Examples

if &price > &old_price and instr(&code, 'M', 1) > 0
  add 1 to #price_count
  if #price_count > 50
    show 'More than 50 prices found.' noline
    input $x 'Continue? (Y/N)'
    if upper($x) = 'N'
      stop
    end-if
  end-if
  else
    add 1 to #old_price_count
end-if
if #rows   ! Will be TRUE if #rows is non-zero.
  do print-it
end-if
if $date1 > 'Apr 21 1996 23:59'
  do past_due
end-if

See Also