// Instead of this: text += cars[0] + "<br>"; text += cars[1] + "<br>"; text += cars[2] + "<br>"; text += cars[3] + "<br>"; text += cars[4] + "<br>"; text += cars[5] + "<br>";
// You can write this:
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
for (statement 1; statement 2; statement 3) {
code block to be executed
}
for (i = 0; i < 5; i++) {
text += "The number is " + i + "
";
}
var person = {fname:"John", lname:"Doe", age:25};
var text = "";
var x;
for (x in person) {
text += person[x];
}
while (condition) {
code block to be executed
}
while (i < 10) {
text += "The number is " + i;
i++;
}
do {
code block to be executed
}
while (condition);
do {
text += "The number is " + i;
i++;
}
while (i < 10);
* Examples and content from W3Schools.com.