Do while loops exercise

hi guys,me again,with different statement.

var i = 0;

function incrementVariable() {
  i = i + 1;
}

do {
  console.log("doo-bee-doo-bee-doo");
  incrementVariable();
} while (i < 5);

Remember how we couldn’t be sure with the plain while loop above that the body would run using maybeTrue()? With do, we can be sure that the body will run!

TODO: Define a function called doWhileLoop in loops.js. The function should take an array as an argument. Use the incrementVariable() function (you can copy it from this README) as the condition, and remove elements from the array until the array is empty or until incrementVariable() returns false. (Your condition might look something like array.length > 0 && incrementVariable().) Finally, return the array.

Define a function called doWhileLoop in loops.js. The function should take an array as an argument. Use the incrementVariable() function (you can copy it from this README) as the condition, and remove elements from the array until the array is empty or until incrementVariable() returns false. (Your condition might look something like array.length > 0 && incrementVariable().) Finally, return the array.

Hi Randel,

I wanted to understand the process; I was able to do this through trial and error but I am not sure what the universal approach is:

  1. must I always declare a variable in such a case?
  2. for the increment value, i = i + 1; I am confused why I need to use this instead of i = i - 1 as “remove elements… is emptry or… returns false” made be think I should be decreasing the count?

Any thought? Here is my code:

function doWhileLoop(array) {
  
  var i = 0; 
  
  function incrementVariable() {
  i = i + 1;
}
do{
  array.pop();
  incrementVariable();
}
while (array.length > 0 && incrementVariable());
return array ;
}