> For the complete documentation index, see [llms.txt](https://docs.plumvoice.com/dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.plumvoice.com/dev/voicexml/tags/if-tag.md).

# \<if>

## \<if> <a href="#if" id="if"></a>

The `<if>` element is used for conditional logic. It has optional `<else>` and `<elseif>` elements.

### Attributes

<table><thead><tr><th width="134.33333333333331">Name</th><th width="177">Data type<select><option value="027671a5361d493aa38b444f5aba5cfc" label="String" color="blue"></option><option value="7fcb007e91384c37becdf626789123f6" label="Integer" color="blue"></option><option value="ffa7910e0cdf455187d1da736f2cb146" label="Boolean" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>cond</td><td><span data-option="027671a5361d493aa38b444f5aba5cfc">String</span></td><td>An ECMAScript expression to evaluate.</td></tr></tbody></table>

### Notes

Note that the `<else>` and `<elseif>` tags both must contain a trailing forward slash to terminate.

{% tabs %}
{% tab title="Correct example" %}

```markup
<if cond="number==5">
  <!-- do something -->
<elseif cond="number==2"/>
  <!-- do something else -->
<else/>
  <!-- do something for all other cases -->
</if>
```

{% endtab %}

{% tab title="Incorrect example" %}

```markup
<if cond="number==5">
  <!-- do something -->
<elseif cond="number==2">
  <!-- this won't work since we left off the / -->
<else>
  <!-- this also won't work since we left off the / -->
</if>
```

{% endtab %}
{% endtabs %}

### Example

```markup
<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <field name="myprompt" type="digits">
      <prompt>
        Say the magic number between 1 and 9.
      </prompt>
      <filled>
        <!-- The "cond" attribute within an "if" tag -->
        <!-- should contain a boolean ECMAscript expression. -->
        <if cond="myprompt==5">
          <prompt>
            You guessed correctly!
          </prompt>
        <elseif cond="myprompt==4 || myprompt==6"/>
          <prompt>
            You're close. Try again.
          </prompt>
          <clear namelist="myprompt"/>
        <else/>
          <prompt>
            Try again.
          </prompt>
          <clear namelist="myprompt"/>
        </if>
      </filled>
    </field>
  </form>
</vxml>
```

The output of the above script would be:

> Computer: Say the magic number between one and nine.\
> Human: Three.\
> Computer: Try again. Say the magic number between one and nine.\
> Human: Six.\
> Computer: You're close. Try again. Say the magic number between one and nine.\
> Human: Five.\
> Computer: You guessed correctly!

### Child Tags

[\<audio>](/dev/voicexml/tags/audio-tag.md), [\<assign>](/dev/voicexml/tags/assign-tag.md), [\<clear>](/dev/voicexml/tags/clear-tag.md), [\<data>](/dev/voicexml/tags/data-tag.md), [\<disconnect>](/dev/voicexml/tags/disconnect-tag.md), [\<else>](/dev/voicexml/tags/else-tag.md), [\<elseif>](/dev/voicexml/tags/elseif-tag.md), [\<enumerate>](/dev/voicexml/tags/enumerate-tag.md), [\<exit>](/dev/voicexml/tags/exit-tag.md), [\<foreach>](/dev/voicexml/tags/foreach-tag.md), [\<goto>](/dev/voicexml/tags/goto-tag.md), [\<if>](/dev/voicexml/tags/if-tag.md), [\<log>](/dev/voicexml/tags/log-tag.md), [\<prompt>](/dev/voicexml/tags/prompt-tag.md), [\<reprompt>](/dev/voicexml/tags/reprompt-tag.md), [\<return>](/dev/voicexml/tags/return-tag.md), [\<script>](/dev/voicexml/tags/script-tag.md), [\<submit>](/dev/voicexml/tags/submit-tag.md), [\<throw>](/dev/voicexml/tags/throw-tag.md), [\<value>](/dev/voicexml/tags/value-tag.md), [\<var>](/dev/voicexml/tags/var-tag.md)

### Parent Tags

[\<block>](/dev/voicexml/tags/block-tag.md), [\<catch>](/dev/voicexml/tags/catch-tag.md), [\<error>](/dev/voicexml/tags/error-tag.md), [\<filled>](/dev/voicexml/tags/filled-tag.md), [\<foreach>](/dev/voicexml/tags/foreach-tag.md), [\<help>](/dev/voicexml/tags/help-tag.md), [\<if>](/dev/voicexml/tags/if-tag.md), [\<noinput>](/dev/voicexml/tags/noinput-tag.md), [\<nomatch>](/dev/voicexml/tags/nomatch-tag.md)
