<foreach>

Description

(VoiceXML 2.1 feature) Iterates through the given ECMAScript array and repeats the enclosed content.

 

Note 1: <foreach> will not create its own scope; all ECMAScript operation within the tag will be done in the parent's scope.

 

Note 2: The <foreach> element operates on a shallow copy of the array specified by the array attribute.

Syntax


<foreach array="ECMAScript_Expression" item="ECMAScript_Variable"> child elements </foreach>

Attributes

Attribute

Description

array

An ECMAScript expression to be evaluated and used as the array. Required.

item

An ECMAScript variable that will store the array item upon each iteration of the loop.  A new variable will be declared if it is not already defined within the parent's scope.  Required.

Attribute Notes

Parents

Block Catch Error Filled ForEach Help If Noinput Nomatch Prompt

Children

Assign Audio Clear Data Disconnect Enumerate Exit ForEach Goto If Log Mark Prompt Reprompt Return Script Submit Throw Value Var Speech Markup (SSML) Tags #PCDATA

VoiceGenie Extensions

None

Limitations/Restrictions

Example


<?xml version="1.0"?> <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <block> <var name="numbers" expr="new Array(1, 2, 3, 4, 5)"/> <foreach array="numbers" item="i"> The square of <value expr="i"/> is <value expr="i*i"/>. </foreach> </block> </form> </vxml>