> 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)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.plumvoice.com/dev/voicexml/tags/if-tag.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
