The basic syntax is:
while(boolean condition)
For example:
var cond = false;
while(cond == false) {
// do something
if(something happens) {
cond = true;
}
// more processing
}
What happens if you want to be able to leap out of the middle of a loop?
var answer = 0;
var correct = 42;
var done = false;
var cnt = 0;
while((done = false) && (cnt < 3)) {
answer = prompt("What is answer to the meaning of life?", "0");
if(answer = correct) {
done = true;
}
else {
cnt++;
}
}
or
for(cnt = 0; cnt < 3; cnt++) {
answer = prompt("What is What is answer to the meaning of life?", "0");
if(answer = correct) {
break;
}
}