NairnFEAMPM Icon

Conditional Commands

The if, ifStr, ifDef, and ifNDef commands are used to define conditional blocks. The if command is for numeric comparisons; the ifStr commands is for string comparisons; the ifDef and ifNDef commands are to checked if variables have been defined. The format of a conditional block is:

if (num1) (op) (num2)
  (block of commands if numeric comparison is true)
    .
else ifStr (string1) (op) (string2)
  (block of commands if string comparison is true)
    .
else if (num1)
  (block of commands if (num1) is not zero)
    .
else ifStr (string1)
  (block of commands if (string1) is not empty)
    .
else ifDef #varName
  (block of commands if #varNam is a defined variable)
    .
else ifDef objName
  (block of commands if objName in an internal script is a defined object name)
    .
else ifNDef #varName
  (block of commands if #varNam is not a defined variable)
    .
else ifNDef objName
  (block of commands if objName in an internal script is not a defined object name or is type None)
    .
else ifNum #varName
  (block of commands if #varNam is a defined variable with a numeric value)
    .
else
  (block of commands if no prior condition is true)
endif

where there can be any number of conditionals and each can be of any type. If either arguments to an if conditional are strings instead of numbers, that conditional will automatically be converted to an ifStr command. In other words, there is no need to use ifStr unless you explicit want to compare two strings as strings when they happen to also be valid numbers. The arguments to ifDef and ifNDef must be a single variable name.

Numerical conditionals compare (num1) to (num2) with the following comparison operators for (op):

String conditionals are nearly the same except ordering is alphabetical order instead of numerical order. Furthermore the two "equals" operators provide case-insensitive or case-sensitive comparisons as follows:

Some string functions can be used to implement other types of useful string comparisons. For example:

The ifNum command can be followed by any expression but it is normally followed by a single variable and this conditional checks whether or not that variable contains a numeric value. Using non-numeric variables in numeric expressions causes an error. This conditional can be used to check variables, if needed, to trap such errors.

Notes

  1. When a numeric conditional has only a single number and no comparison operator (such as if (num1)), the conditional is true if the number is not equal to zero. If the number is not zero, the conditional is false.
  2. When a string conditional has only a single string and no comparison operator (such as ifStr (string1)), the conditional is true if the string is not an empty string. If the string has text, the conditional is false.