Loop review

Looping statements are used in JavaScript to execute a series of statements until a specified conditional statement evaluates to true.

While statement

The 'while' statement executes as long as the conditional specified evaluates to True. The conditional is checked before the statements in the loop are executed. The syntax for the 'while' statement is:

while(conditional)
	statements;

For statement

The 'for' statement is similar to the while statement, except that it adds an initial statement, which is executed before the first loop, and it also adds an iteration statement, which is executed at the end of each cycle. The syntax for the 'for' statement is:

for(initial; conditional; iteration)
	statements;

Break and continue statements

The 'break' and 'continue' statements are used to alter the execution of a looping statement regardless of the conditional statement in the loop. The continue statement causes the remaining statements inside a loop body to be skipped, and program execution is returned to the conditional statement. The break statement, on the other hand, will automatically exit a loop, and program execution will move to the next statement following the loop.

Arrays

Arrays are a series of variables grouped together by a common name. You can create an array using the following syntax:

var myArray = new Array();

Individual array elements can then be accessed using their appropriate numeric index:

myArray[0] = "This is the first array element";
document.writeln(myArray[0]);