LOOPS

For what?

CONDITION VS. LOOP

condition vs. loop flowchart

WHILE LOOP

Syntax

while (condition) {
    //code block to be executed
}

Example

while(confirm("Do you want a kiss?")) {
    document.getElementById("cheek").innerHTML +="KISS ";
}

WHILE IN ACTION

jsbin

FOR LOOP

Syntax

for (initialization; condition; update) {
    //code block to be executed
}

Example

for(var i=0; i<100; i++) {
    document.getElementById("cheek").innerHTML +="KISS ";
}

FOR IN ACTION

jsbin

WHILE VS. FOR

How to choose?

ENDLESS LOOP

How to avoid them?