<foreach>

Iterates over the elements of an array.

Syntax

 <foreach
     item="string"
     array="string"
 >
   Executable Content
 </bevocal:foreach>

Description

The interpreter sets the iteration variable to each element of the array, in turn, and executes the contained elements once for each setting of the iteration variable.

Attribute Description
item

Name of the iteration variable, which may not be a JavaScript reserved keyword.

The scope of the iteration variable is the <foreach> element.

array

The name of a variable whose value is an array.

Usage

Parents Children
<block>
<catch>
<error>
<filled>
<foreach>
<help>
<if>
<noinput>
<nomatch>
<assign>
<audio>
<bevocal:connect>
<bevocal:dial>
<bevocal:disconnect>
<bevocal:hold>
<bevocal:whisper>
<clear>
<data>
<disconnect>
<exit>
<foreach>
<goto>
<if>
<log>
<prompt>
<reprompt>
<rethrow>
<return>
<script>
<send>
<subdialog>
<submit>
<throw>
<value>
<var>

See Also

None

Examples

 <?xml version="1.0" ?>
 <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
  "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
 
 <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
   <form id="form1">
     <block>
       <!-- create an array of services -->
       <var name="serviceNames" 
         expr="new Array('news', 'weather', 'traffic')"/>
       <prompt>Here's a list of services </prompt>
       <!-- iterate through each item in the services array -->
       <foreach item="service" array="serviceNames">
         <!-- Say the current array element -->
         <prompt><value expr="service"/> <break size="small"/></prompt>
       </foreach>
     </block>
   </form>
 </vxml>
 

[Show Frames]   [FIRST] [PREVIOUS] [NEXT]
BeVocal, Inc. Café Home | Developer Agreement | Privacy Policy | Site Map | Terms & Conditions
Part No. 520-0001-02 | © 1999-2007, BeVocal, Inc. All rights reserved | 1.877.33.VOCAL