I cannot figure out why this is returning 1 instead of 7.
const getNextEventCountTest = () => {
let sum = 0;
let q = 0;
do {
sum = sum + 0.5
}
while (sum < 4){
q = q + 1;
}
return q;
};
do-while is good here, since I want to always run the first code block but only conditionally increment q.
But this:
console.log(getNextEventCountTest()); => 1
whereas this has the right behavior:
const getNextEventCountTest = () => {
let sum = 0;
let q = 0;
// this is desired behavior:
while (sum < 4){
sum = sum + 0.5
if(sum < 4){
q = q + 1;
}
}
return q;
};
do { ... } while(condition); { ... }. Notice the added semicolon