The While Loop
while (condition) {
code block to be executed
}
while (i < 10) {
text += "The number is " + i;
i++;
}
var cars = ["BMW", "Volvo", "Saab", "Ford"];
var i = 0;
var text = "";
while (cars[i]) {
text += cars[i] + "<br>";
i++;
}
The Do/While Loop
do {
code block to be executed
}
while (condition);
do {
text += "The number is " + i;
i++;
}
while (i < 10);
The For Loop
for (statement 1; statement 2; statement 3) {
code block to be executed
}
for (i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
The For/In Loop
var person = {fname:"John", lname:"Doe", age:25};
var text = "";
var x;
for (x in person) {
text += person[x];
}