GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialrepublic.com — JavaScript While, Do-While, For and For-In Loops - Tutorial Republic JAVASCRIPT BASIC
JS Introduction
JS Getting Started
JS Syntax
JS Variables
JS Generating Output
JS Data Types
JS Operators
JS Events
JS Strings
JS Numbers
JS If…Else
JS Switch…Case
JS Arrays
JS Sorting Arrays
JS Loops
JS Functions
JS Objects
JAVASCRIPT & DOM
JS DOM Nodes
JS DOM Selectors
JS DOM Styling
JS DOM Get Set Attributes
JS DOM Manipulation
JS DOM Navigation
JAVASCRIPT & BOM
JAVASCRIPT ADVANCED
JS Date and Time
JS Math Operations
JS Type Conversions
JS Event Listeners
JS Event Propagation
JS Borrowing Methods
JS Hoisting Behavior
JS Closures
JS Strict Mode
JS JSON Parsing
JS Error Handling
JS Regular Expressions
JS Form Validation
JS Cookies
JS AJAX Requests
JS ES6 Features
JAVASCRIPT EXAMPLES
JAVASCRIPT REFERENCE
Advertisements
JavaScript LoopsIn this tutorial you will learn how to repeat a series of actions using loops in JavaScript. Different Types of Loops in JavaScriptLoops are used to execute the same block of code again and again, as long as a certain condition is met. The basic idea behind a loop is to automate the repetitive tasks within a program to save the time and effort. JavaScript now supports five different types of loops:
In the following sections, we will discuss each of these loop statements in detail. The while LoopThis is the simplest looping statement provided by JavaScript. The
while(condition) {
// Code to be executed } The following example defines a loop that will continue to run as long as the variable ExampleTry this code »
Note: Make sure that the condition specified in your loop eventually goes false. Otherwise, the loop will never stop iterating which is known as infinite loop. A common mistake is to forget to increment the counter variable (variable The do...while LoopThe
do {
// Code to be executed } while(condition); The JavaScript code in the following example defines a loop that starts with ExampleTry this code »
Difference Between while and do...while LoopThe With a The for LoopThe
for(initialization; condition; increment) {
// Code to be executed } The parameters of the
The following example defines a loop that starts with ExampleTry this code »
The ExampleTry this code »
The for...in LoopThe
for(variable in object) {
// Code to be executed } The loop counter i.e. variable in the The following example will show you how to loop through all properties of a JavaScript object. ExampleTry this code »
Similarly, you can loop through the elements of an array, like this: ExampleTry this code »
Note: The The for...of Loop ES6ES6 introduces a new The following example will show you how to loop through arrays and strings using this loop. ExampleTry this code »
To learn about other ES6 features, please check out the JavaScript ES6 features chapter. Note: The Advertisements
Advertisements
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |