Normal execution of the script proceeds from the top to the bottom, one statement at a time. This makes for a not very flexible or capable program.
Conditional execution of one section of code or another allows the execution flow to be controlled according to the result of a computation that yields a Boolean result. These either conditionally execute a piece of code, or not as is the case with the if() construct, or conditionally execute either one fragment of code or another as is the case with the if()else construct. The ternary operator ?: provides an alternative way to construct an if()else mechanism at the expense of readability and potential obfuscation of your script.
Iterators are used to cycle round a section of code repeatedly until some condition is met.
A for() iterator will normally be used to index a counter to enumerate through a set of items, possibly in an array.
A while() iterator will execute the same code over and over until something in that code block changes the value of the condition at the head of the while() block.
Reserved words (as of ECMA edition 2) suggest that do() iterators and switch()case trees will be introduced later, or may be implemented now by forward looking JavaScript interpreter builders. Edition 3 of the standard introduces these and a mandatory requirement.
Prev | Home | Next |
Floating point constant | Up | focus() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |