|
The switch statement is similar to if else
statement, it presents the script with a serious of alternative
routes that depend on conditions found. The switch statement
is cleaner than nesting a series of If else statements.
Syntax :
switch ( expression ) {
case( value ) : { statement;
break; }
case( value ) : { statement;
break; }
default : statement; }
Example :
var gt = new
Date( ); var gt = gt.gethours;
switch ( gt); {
case( 12) : {
document.write(
"It 12 in the Afternoon");
break; }
case(13) : {
document.write(
"It is one in the Afternoon");
break; }
default
: document.write("It is two in the Afternoon");
}
In this exercise, you will learn SWITCH loop using Script tag.
JavaScript includes the switch statement. This
statement includes the value to test(in this case, w) in the
parentheses. Each of these statements specifies a value to
compare with the value specified in the switch statement.
If the value matches, the statements after the case statement
are executed. Otherwise, the next case is tried.
The break statement is used to end each case.
Type Layout Galaxy, Image Online or Donate Blood in the first
text field and Click the button "Click Me" to view
the result in the second text field.
A break statement ends a series of while
or for statements. Sometimes you want a condition that ignores
everything else and jumps out of the loop to carry on with
the rest of the script. This is done with a break statement.
Syntax :
break;
Example :
While ( counter < 100) {
if ( counter >= 99 ) {
break;
document.write(counter);
document.write("<br>");
} }
Like break statement, continue breaks out
of a "for" or a "while" loop. Instead
of going to the next set of instructions past the loop, the
continue statement sends the script back to the condition
in the while statement or to the update expression in a "for" loop.
Syntax :
continue;
Example :
While ( counter < 100) {
if ( counter >= 99 ) {
continue;
document.write(counter);
document.write("<br>");
} }
Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.
|
|