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

  Looping Statements

Some times you need to run a statement multiple times rather than just once .Two looping statements are supported by JavaScript to carry out this task. The two statements are for loop and while loop.

For Loops
While Loops

  For Loops

It is ideal for situations in which you want a group of instructions to occur a specified number of times.

Syntax :

For ( condition ) {
              Statement ……
}

Example :

For ( var counter = 1; counter < = 10; ++counter ) {
              document.write(counter);
}

In this exercise, you will learn FOR loop using Script tag.

In FOR loop, a variable count is declared and set to a value of 0. Then a test is made to see whether the value of count is less than or equal to w. The value of count is incremented by 1 by the statement count++. The process proceeds until the value of count is greater than w. Where w is the value that you are going to enter.

Type any Number in the first text field and Click the button "Click Me" to view the result in the second text field.


  While Loops

The while loop, is better suited to situations in which the number of loops required is to be determined by an outside source.

Syntax :

While ( condition ) {
              Statement………..
}

Example :

While ( counter < 100) {
              If ( counter >= 99 ) {
                           document.write("Counter is less than equal to 99");
              }
}

  WHILE Statement

In this exercise, you will learn While loop using Script tag.

JavaScript includes the while loop,this while loop will be executed as long as the condition is true, if the condition is false, the statements might not execute at all. With each iteration, the loop increments n.

Type any Number in the first text field and Click the button "Click Me" to view the result in the second text field. The result gives the number of iterations in the while loop.

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-21645588, 91-22-21640585 Fax : 91-22-21641545
Email : ionline@vsnl.com
© Image Online 2001-2003