9. Why it is a infinity loop?


#1

Hello!

I made this code and apparently it loops for eternity, but i do not understand why!

var ok = true

var getToDaChoppa = function(){
  do {
      console.log("FIRST!");
    } while (ok) {
        console.log("Hello!");
        ok = false
    }
}
getToDaChoppa();

#2

Because that is not how do while loops work. This is your do while loop:

  do {
      console.log("FIRST!");
    } while (ok)

which is an infinite loop and this:

 {
        console.log("Hello!");
        ok = false
    }

is regular code in unnecessary {} that is executed when the loop is done.