< foreach >
Description
Iterates through an ECMAScript array of items. New in VoiceXML 2.1.
Syntax
<foreach array = "ECMAScript_Expression" item = "variable" />
Attributes
| array | An ECMAScript expression that evaluates to an array. Required. |
| item | The variable that stores each array item upon each iteration of the loop. Required. |
Parents
<block>, <catch>, <error>, <filled>, <foreach>, <help>, <if>, <noinput>, <nomatch>, <prompt>
Children
<assign>, <audio>, <break>, <clear>, <data>, <disconnect>, <enumerate>, <exit>, <foreach>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>
Extensions
None.
Limitations/Restrictions
None.
Example Code
<?xml version="1.0"?>
<vxml version="2.1"
xmlns="http://www.w3.org/2001/vxml">
<form id="play_fruit">
<block>
<!-- create an array of fruit names -->
<var name="aFruit" expr="new Array('apples', 'oranges', 'pears', 'bananas')"/>
Here's a list of fruit we have available today
<!-- iterate throught through each item in the array -->
<foreach item="fruit" array="aFruit">
<value expr="fruit"/>
</foreach>
</block>
</form>
</vxml>