using loops in javascript

Post on 17-Sep-2015

230 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

loops

TRANSCRIPT

Using loops in JavaScript

Using loops in JavaScript 6 Mar 2014The main strength of any programming language is its ability to process blocks of code repeatedly. JavaScript, like other programming languages, provides us with loop. Statements placed inside loops are executed a set number of times... or even infinitely.

Loops can be introduced by using any one of the three statements; for, whileanddo...while

Here is the format of aforloop:

for (Initialization statements; Condition; Updation statements)

{

...

statements

...

}

When the JavaScript interpreter comes across aforloop, it executes the initialization statements and then checks the condition. Only when the condition returns 'true', the interpreter enters the loop. After the first iteration, the updation statements are executed and then the condition is evaluated again. This continues till the condition returns 'false' and the loop stops.

Displaying the 12 times table in an alert box

var msg = "";

var res = "0";

for (var x = 1; x

top related