JavaScript Kit > JavaScript Reference > JavaScript Statements > Here
JavaScript Statements- Looping
JavaScript Statements enable you to implement logic, looping, and more within your script.
Related Tutorials
- Understanding basic arrays and loops
- Variable and expression shortcuts
- The switch statement of JavaScript1.2
- JavaScript and OOP
- Creating custom objects in JavaScript
Looping Statements
| Statements | Description |
|---|---|
| for | Probably the common looping statement,
"for" executes the enclosed statements any desired number of times. Syntax: for (initialValue; test; increment) Example: for (x=0; x<3; x++) |
| while | A while loop continuously executes the
enclosed statements as long as the tested expression evaluates to
true. If the expression is false to begin with, the entire while
loop is skipped. Syntax: while (expression) Example: var number=0 |
| do/while | The do/while statement differs from the
standard "while" in that the expression tested for is put at the
end, ensuring that a do/while loop is always executed at least
once.. Syntax: do Example: var number=0 |
| for/in | For/in is a special looping statement
that lets you display the property names (or properties' value) of
an object. Syntax: for (variable in object) "variable" is any arbitrary variable that will hold the current property of the object in question as it is being looped. Here are two examples. Example 1: This example writes out all the properties of the "navigator" object: for (myprop in navigator) Example 2: This example writes out the properties, plus their corresponding value, of the "navigator" object: for (myprop in navigator)
|
| break | The break statement causes an exit of
the innermost loop the statement is contained in. It's useful to
prematurely end a loop: Example: for (i=0; i<6;
i++){ |
| continue | The continue statement causes
JavaScript to skip the rest of the statements that may follow in a
loop, and continue with the next iteration. The loop is not
exited, unlike in a break statement. Example: for (i=1; i<6;
i++){ |
- JavaScript Operators
- JavaScript Statements
- Global functions
- Escape Sequences
- Reserved Words
- Anchor
- Applet
- Area
- Array
- Boolean
- Date
- Document
- Event
- Form
- Reset
- Frame
- Function
- History
- Image
- Link
- Location
- Math
- Navigator
- Number
- Object
- RegExp
- Screen
- String
- Style
- window

