Anyone know why my code is ending at 5 and not skipping it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Anyone know why my code is ending at 5 and not skipping it

https://code.sololearn.com/cEKb5yNS7O72/?ref=app

20th May 2021, 7:47 AM
Unknown Guy
2 Answers
+ 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 );
20th May 2021, 8:27 AM
Ipang
+ 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);
20th May 2021, 12:22 PM
visph
visph - avatar