Changes

JavaScript Flow Control and Looping

440 bytes added, 14:27, 24 April 2007
JavaScript ''switch'' Statements
''if ... else'' constructs work fine if you need to check a value against criteria (for example checking the value of a string against a couple of possible candidates as follows:
 
<pre>
if (customerName = "Fred")
{
document.write ("Hello Fred!");
}
else if (customerName = "John")
{
document.write ("Hello John!");
}
else
{
document.write ("You're not Fred! Where's Fred?");
}
</pre>
 
This can become cumbersome when a need arises to evaluate a large number of conditions. An easier way to handle such situations is to use the ''switch'' statement, the syntax for which is as follows:
 
<pre>
</pre>