Skip to main content

<Do>

The <Do> conditional allows you to implement Do/While style looping.

<Do> Attributes​

<Do> supports the following attributes that change its behavior:

AttributeAllowed ValuesDefault Value
expressionstring expression to evaluatenone
maxLoopsinteger > 01

expression​

The expression attribute accepts a string of conditionals to evaluate. If the expression evaluates to true, then all verbs nested inside <Do> are executed. Otherwise, the nested verbs are ignored and the next VoXML instruction is executed.

maxLoops​

The maxLoops attribute sets the maximum number of loops to execute before exiting the <Do> loop.

<Do> Examples​

Simple Usage​

Prompt the caller up to 3 times to enter DTMF 1 or 2.

<Response>
<Do expression="${menu.digits}!~(1|2)" maxLoops="3">
<Gather input="dtmf" output="menu">
<Say>Hello. Press 1 to speak with support or 2 to speak with sales.</Say>
</Gather>
</Do>
</Response>

Advanced Usage​

Prompt the caller up to 3 times for a six-digit account number, then read it back to them.

<Response>
<Do expression="${account.digits}!~[0-9]{6}" maxLoops="3">
<Gather input="dtmf" output="account" finishOnKey="#">
<Say>Please enter your six-digit account number followed by the pound key.</Say>
</Gather>
</Do>
<Say>You entered ${account.digits}.</Say>
</Response>