| HTML | CSS | JavaScript |XHTML, XML, ASP, |
JS BasicsJS HomeIntroduction Basics Operators Functions Conditional Looping JS ReferencesString ObjectArray Object Date Object Math Object Window Object Frame Object Form Object Browser Object |
JavaScript String LoopingWhen 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. whileThe while statement will execute if the condition is true
while(condition){
[statement(s)]
}
do...whileThe 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 loopThe 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. |