can anyone help me with this problem, i did the loop 3 assessment using for loop at first, it worked , but when i try to change the same code to use either while or do while loop , the code didn’t work , its just goes on loop and try to crash the browser. can you please assess my code and tell me where i might have done wrong? plus i have noticed, if i don’t use continue statement, the code works fine. but here i am confused why does it work even if i use continue statement with for loop but not with while or do… while loop? https://codepen.io/div_ya/pen/OJNzZOK
Hello @divyabk54
in the do while code you write
do{
if(isPrime(i) === false){
continue;
}else{
para.textContent += i + ', ';
}
i--;
}while(i > 1)
so when it find a non prime number it will start the while block without changing the the value of i so it keep test the same value of i forever so you just need to add i–; before the continue statements
hope that help and have a nice day
hope that help and have a nice day
1 Like
thank you very much!, it really helped. i never look at it like that.
hope you have nice day too.
you very welcome and glad it helped and thanks
1 Like