Can someone tell me what im doing wrong?


#1

This is causing my browser to crash but i cant see where the loop is infinite

// Write your code below!
var num1 = true;
do {
    console.log("well i messed up the first time!....");
}
while (num1){
    console.log("this should set it to false");
    num1 = false;
}
for(var i = 5;i > 0; i--){
    console.log("i hope i dont break this time!");
}

#2

Nevermind, it seems i didnt understand completely how the do/while loop works


#3

syntax:
do...while

do {
    code block to be executed
}
while (condition);

syntax:
while loop

while (condition) {
    code block to be executed
}

you mixed do...while and while loop


#4

from w3schools:

The do/while statement creates a loop that executes a block of code once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.

The do/while statement is used when you want to run a loop at least one time, no matter what.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.