A.4. Flow control

ECMAScript provides many flow control structures for controlling the execution of a program. These are summarized in Table A-4.

Table A-4. Summary of ECMAScript flow control structures
Flow control structureDescriptionExample
if...elseif...elseIf a given expression evaluates to true, an associated block of code will be executed, otherwise zero or more elseif conditions will be checked, and if none evaluates to true, a final else block of code will be executed (the else part is optional).
if(x < 3){
  x += 1;
} elseif(x < 1) {
  x += 2;
} else {
  x = 0;
}
forA loop with a built-in counter initialization, conditional check, and counter advance.
for(x = 0; x < 10; x++){
  y = y + x;
}
for...inA loop over each property of an object.

Get Definitive VoiceXML™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.