Assessment request for Loops 3 skill test ( confused on using continue statement with loops)

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?

Hello @divyabk54

in the do while code you write

      if(isPrime(i) === false){
        para.textContent += 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 :slight_smile:

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. :slightly_smiling_face:

you very welcome and glad it helped and thanks :slight_smile:

1 Like