#IF

#IF( condition )

truestatements

[ #ELSEIF( condition )

truestatements ]

[ #ELSE falsestatements ]

#END

conditionA logical expression.
truestatementsThe Template statements to execute if the condition is true.
#ELSEIFOptional. Provides structure for statements to execute if its condition is true.
#ELSEOptional. Provides structure for statements to execute if the condition is false.
falsestatementsOptional. The Template statements to execute if the condition is false.
#ENDThe #IF structure terminator.

The #IF structure evaluates the condition and executes either the truestatements or falsestatements (if present). This statement may be used outside an XML scope and does not require a previous LOADXML to instantiate an XML scope.

Example:

  // This script creates a set attribute definition of the 1st 10
  // natural numbers and defines an attribute named "Set10"
  
  #DECLARE (SetString);
  #DECLARE (Ndx);
  #SET (SetString, '[');   //initialize SetString to [
  #SET (Ndx, 1);          //initialize Ndx to 1
  #LOOP
     #IF (%Ndx% > 9)      //if we've iterated 9 times
        #BREAK            // break out of the loop
     #ELSE                //otherwise
        #APPEND (SetString, %'Ndx'% + ',');
                          //append Ndx and comma to SetString
     #SET (Ndx, %Ndx% + 1);
                          //and increment the value of Ndx
     #END
  #END
  
  #APPEND (SetString, %'Ndx'% + ']'); //add 10th element and closing ]
  
  EXPORT Set10 := %'SetString'%; //generate the ECL code
                         // This generates:
                         // EXPORT Set10 := [1,2,3,4,5,6,7,8,9,10];

See Also: #LOOP, #DECLARE