Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Looping In Java Script

                         

In this article you learn the basics of JavaScript and create your first JavaScript program.

What is JavaScript loop?
 The JavaScript loops used to execute the same block or code a specified number of times and while a specified condition. JavaScript loops Very often write code, you want the same block of code to run over and over again in a row. The Instead of adding several almost equal lines in a script we can use loops to perform a task.

JavaScript supported Two different type looping :-
 1.The For Loop
 2.The while Loop

 For Loop:
The JavaScript for loop is used the know in advance how many times of the script should run.  JavaScript loop Use a For loop to run time same block of code a specified the number.

Example:

<html>
<body>
<script language="javascript">
var i=0
for (i=0;i<=6;i++)
{
alert("The number is " + i)
}
</script>
</body>
</html>


The while Loop:
The while loop is used when the loop to execute and continue executing while the specified condition

<html>
<body>
<script language="Javascript">
var i=0
while (i<=10)
{
document.write("serial number" + i)
document.write("<br />")
i=i+1
}
</script>
</table>
</body>
</html>


The do while loop
The JavaScript do...while loop is a variant of the while loop. The loop will be always execute a block of code once and then it will repeat the loop as long as the specified condition is true. This loop will be always executed once, even if the condition is false, because the loop code are executed before the condition is tested.

 Example:

<html>
<body>
<script language="Javascript">
var i=0
do 
{
alert("number" + i)
i=i+1
}
while (i<3)
</script>
</table>
</body>
</html>

 

The for in:
This is not same as the for loop . The javascript for...in loop is used to provide to the enumerate properties of a JavaScript object . This loop only found in JavaScript . This statement in the loop are executed for each property of an object until every property has been accessed.

Example:

<html>
<head> 
<Script language="Javascript">
var i;
var num= new Array(8,4,5,7,10);
for(i in num)
{
document.write(" " ,num[i]);
document.write("<br />")
}
</script>
</head>
</body>
</html>

Javascript looping Break and continue
There are two statements supported in javascript used in loop:- Break and continue

Break:
The JavaScript break command will break the loop and continue executing the code the follows after the loop.

Example:

<html>
<head>
<Script language="Javascript">
var i=0
for (i=0;i<=6;i++)
{
if (i==3){break}
alert("number" + i)
}
</script>
</head>
</body>
</html>

Continue:
The JavaScript continue command will be break the current loop and continue with the next value. 

Example

 

<html>
<head>
<script language="JavaScript">
var i=0;
for (i=0;i<=8;i++)
{
if (i==4){continue}
document.write("value" + i)
document.write("</br>")
}
</script>
</head>
</body>
</html>

 

 

                         

Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.