According to MDN, do while loop states that this is the syntax and do runs once despite the condition
do statement while (condition);
The following is my code
let mergeArr3 = (arr1 , arr2) => {
let i = 1;
do {
console.log('hello') //prints hello 5 times
i++;
}
while (i < 6 ) {
console.log(i) //prints 6
console.log('world') // prints world once
}
}
mergeArr3(arr1 , arr2)
I am struggling to understand two things:
Why does
console.log(i)print6when 6 < 6 suppose to be evaluated to false and it shouldn't be running that line of code when i === 6.Dois suppose to run once, but why is it running 5 times?
while (i < 6 ); {, for example, and the open brace is part of the next block of code.