0
Anyone know why my code is ending at 5 and not skipping it
2 Respostas
+ 3
Instead of checking <x> == 5, simply check <x> != 5 before deciding whether or not to log in console.
This problem is quite common where the `x++;` line becomes unreachable due to the check on <x> value being combined with `continue` statement, leading to an infinite loop.
let x = 3;
do
{
if( x != 5 )
{
console.log(x);
}
x++;
} while( x < 9 );
+ 1
you could also (pre)increment 'x' directly inside while condition:
let x=3
do{if(x==5){continue}console.log(x)}
while(++x<9);