A.4. Flow control
ECMAScript provides many flow control structures for controlling the execution of a program. These are summarized in Table A-4.
Flow control structure | Description | Example |
---|---|---|
if...elseif...else | If 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; } |
for | A loop with a built-in counter initialization, conditional check, and counter advance. |
for(x = 0; x < 10; x++){ y = y + x; } |
for...in | A 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.