To learn it, you gotta 'do' it


#1


var some= 34;
var getToDaChoppa = function(){
  // Write your do/while loop here!
  do{
      console.log("Something at least once");
  }while(some < 24){
      console.log("This won't be printed");
  }
};

getToDaChoppa();


Why this code prints out two statements instead of one. Second statement shouldn't be printed out, becouse condition is false or am I wrong?


#2

no? A do while loop always execute at least once (thanks to do) then after the first run of the loop the condition gets checked. So it makes sense that both lines are printed

The whole point of a do while loop is that it execute at least once, no matter the conditin


#3

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