Loop Statements in Javascript

for ( var cnt = 0; cnt < 10; cnt++) {
Statements;
}


Do While Loop

Will continue to loop while the specified condition is true. The condition is evaluated at the bottom of the loop

do {
i = i +1
Statements;
} while ( i < 5);


While Loop

Will continue to loop while the specified condition is true.

var cnt= 0;
while( cnt < 5) {
Statements;
cnt ++;
}


For In Loop

The for in loop will cycle through the properties of standard and custom objects.

for (var objectproperty in objectpropertyArray) {
javascript statements
}

The code below will list all the properties associated with the document object (the webpage)

var wholelist= "" ;//empty quotes
for (var i in document) {
wholelist= wholelist+ "document."+ i + "\t" + document[i] +"\n" ;
}
document.displaytxt.result.value =wholelist;
// displaytext is the form name on the page and result is a textarea to print the results in. }

Home
Site Index