# <if>

Description

The `<if>` element is a conditional logic statement that is used with the optional `<elseif>` and `<else>` elements. It is used to define content to be executed in a specific condition.

Syntax

    <if
        cond="ECMAScript_Expression">
      child elements
    </if>

Attributes

Attribute | Description
cond | An ECMAScript expression to be evaluated and used as a boolean value for this conditional logic statement. Required.

Parents

<block>, <catch>, <error>, <filled>, <foreach>, <help>, <if>, <noinput>, <nomatch>

Children

<assign>, <audio>, <clear>, <data>, <disconnect>, <else>, <elseif>, <enumerate>, <exit>, <foreach>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>, #PCDATA

Extensions

None.

Limitations/Restrictions

- `<if>` cannot be used as a child of `<foreach>` when `<foreach>` is a child of `<prompt>`.

Example

    <?xml version="1.0"?>
    <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
      <form>
        <var name="number_var" expr="5"/>
        <var name="boolean_var" expr="true"/>
        <var name="string_var" expr="'hello'"/>
        <block>
          <if cond="number_var != 5">
            The number is not five.
          <elseif cond="!boolean_var"/>
            The boolean is not true.
          <elseif cond="string_var != 'hello'"/>
            The string is not hello.
          <else/>
            The number is five and
            the boolean is true and
            the string is hello.
          </if>
        </block>
      </form>
    </vxml>