Site hosted by Angelfire.com: Build your free website today!
Website Help

| HTML | CSS | JavaScript |

Soon to come:
XHTML, XML, ASP,
Home

JS Basics

JS Home
Introduction
Basics
Operators
Functions
Conditional
Looping

JS References

String Object
Array Object
Date Object
Math Object
Window Object
Frame Object
Form Object
Browser Object

JavaScript String Looping

When you write JavaScript, or any programming language, it is common to have loops which execute a specific block of code according to the condition given.

while

The while statement will execute if the condition is true


    while(condition){
     [statement(s)]
    }
   

do...while

The do...while loop is everyway similar to the while statement except for the fact that the test statement is at the end of the loop, which will let the code to execute at least once.


    do{
     [statement(s)]
    }
    while(condition)
   

for loop

The for loop will execute a block of code a number of times


    for(initialization;condition;increment){
     [statement(s)]
    }
   

The initialization part of the for loop defines the variable which will be used as the loops condition. Eg; if the conditional part of the expressions looks like var loopCounter = 0 and the conditional part of the statement looks like loopCounter < 9 then the code will execute as long as loopCounter is less than 9. the last part of the statement is the incrementer which tells by how much the loopCounter is increased by.

fastadvert.com


fastadvert.com - make money with your website