Untitled Document



 Introduction to HTML
 Structure of HTML
 Creating First HTML  Document
 Building Your HTML  Document
 Tables
 Frames
 Including Images into  Document
 Including Multimedia
 Developing HTML  FORMS
 Using Style Sheet
 Understanding URLs
 Using JavaScript
 Introducing JavaScript
   Using JavaScript
 Introducing to  JavaScript
   What is JavaScript?
 Why should you use  Java Script?
 Structure of a  JavaScript
   Syntax of JavaScript
 JavaScript
 Statements
 
 Statements
 Blocks
 
 Blocks
 Comments
 
   Comments
 Single-Line  Comments
 Multiline Comments
 Data
 
   Data
   Strings
   Numbers
   Boolean
 Null
 Expressions
 
   Expressions
   Numeric Expressions
 Logical Expressions
 Variables
 
   Variables
 Defining and Naming  Variables
 Changing the Value  of a Variable
 Functions
 
   Functions
   Built-in Functions
 User-Defined  Functions
 Returning Values  from Function
 Flow Control
 
   Flow Control
   If and if ....else
   If Statement
   If...else Statement
   IF Statement
   Looping Statements
   For Loops
   While Loops
   WHILE Statement
   Switch Statement
   Break Statement
 Continue Statement
 Objects
 
   Objects
   Methods
   Properties
   Built-in Objects
 User-defined Objects
 Arrays
 
 Arrays
 Event Handlers
 
   Event Handlers
 onMouseOver,  onMouseOut Events
 onClick, onChange  Events Handlers
 Using the onSubmit  Event Handler
 Introduction to Cookies
 
 Introduction to  Cookies
   Sessions Cookies
 Persistent Cookies
 Using Java

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.




  Using JavaScript > Flow Control

  Switch Statement

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.


  Break Statement

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>");
             }
}

  Continue Statement

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>");
            }
}

Back Next


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.




17, Vadsarvala Nivas, 65-A, J. Nehru Road, Mulund (W), Mumbai - 400 080 INDIA
Tel : 91-22-25795588, 91-22-25780444 Fax : 91-22-25793397
Email : ionline@vsnl.com
© Image Online 2001-2003