Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

if

Syntax

if (expression) {
    /* code */
}
else if (expression) {
        /* code */
}
else {
    /* code */
}

Release Information

Statement introduced in version 1.0 of the SLAX language.

Description

Include a conditional construct that causes instructions to be processed if the Boolean expression evaluates to TRUE.

Optionally, you can include multiple else if statements following an if statement to perform additional conditional tests if the expression in the if statement evaluates to FALSE. Multiple else if statements can be included, but the processor only executes the instructions contained in the first else if statement whose expression evaluates to TRUE; all subsequent else if statements are ignored. The optional else statement includes a default set of instructions that are processed if the expressions defined in all associated if and else if statements evaluate to FALSE.

Attributes

expression

Specifies the expression to evaluate.

SLAX Example

var $description2 = {
   if (description) {
      expr description;
   }
   else if (../description) {
      expr ../description; 
   }
   else {
      expr "no description found";
   }
}

XSLT Equivalent

<xsl:variable name="description2">
   <xsl:choose>
      <xsl:when test="description">
           <xsl:value-of select="description"/>
      </xsl:when>
      <xsl:when test="../description">
         <xsl:value-of select="../description"/>
      </xsl:when>
      <xsl:otherwise>unknown</xsl:otherwise>
   </xsl:choose>
</xsl:variable>

Usage Examples

See Example: Configuring Dual Routing Engines, Example: Preventing Import of the Full Routing Table, and Example: Automatically Configuring Logical Interfaces and IP Addresses.

Published: 2013-03-05