10/11 Infinite loop


#1

This is my code for the 10/11.

var getToDaChoppa = function(i){
// Write your do/while loop here!
do {
i = "Hi"
}

while(i === "Hi") {
console.log("I think I understand...?");
var i = "Bye"
}
};

getToDaChoppa("bye");

Somehow, this is a infinite loop, even though I changed i to "Bye" on the 9th line.
What am I doing wrong?


#2

A do while loop runs until the argument in the while is false

do{
i = "Hi" // bye is overwritten with Hi
}
while(i === "Hi") // this is true and the loop begins again

So while is never false and you have a infinite loop


#3

I believe I understand now. Thanks for the reply! :smile: