Development| HTML| JavaScript| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Looping In Java Script 
 

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

 

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>

 

 

                         

» View all related tutorials
Related Tags: java javascript c attributes script reference object method sed remove ip attribute node move nat to ref e it alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.