never ending loop

JavaScript for Loops


The for loop is used when you know in advance how many times the script should run.

Syntax

for (var=startvalue;var<=endvalue;var=var+increment)
{
code to be executed
}

Example


var i=0;
for (i=0;i<=5;i++)
{
document.write("The number is " + i);
document.write("
");

}
 

The example below defines a loop that starts with i=0. The loop will continue to run as long as i is less than, or equal to 5. i will increase by 1 each time the loop runs.
Note: The increment parameter could also be negative, and the <= could be any comparing statement.

Example

If you want a never ending loops, you just decrease your variable.

var i=0;
for (i=0;i<=5;i--)
{
document.write("The number is " + i);
document.write(" ");
}
 

0 Comments:

 

Mhabibie's web | Mhabibie's BLog