+ 1

Please why is this code running into an infinity loop .

https://code.sololearn.com/W244YFWjsoIi/?ref=app please could you help me point out the problem and correct it using the same principle I'm trying to find out the first 10 prime numbers

2nd Apr 2018, 10:47 AM
Sammy
Sammy - avatar
35 Respuestas
+ 2
The variable count is never decreased in value, inside the loop.
2nd Apr 2018, 12:31 PM
Emma
+ 2
move line 3 isPrime=true; inside while loop to line 5 so it is always true at the beginning of the loop.
2nd Apr 2018, 1:34 PM
John Wells
John Wells - avatar
+ 2
mine runs. Did you kill SoloLearn process and restart? Sometimes it gets messed up running bad programs and must be restarted to run anything afterwards,
2nd Apr 2018, 1:51 PM
John Wells
John Wells - avatar
+ 2
when you have your infinite loop or any broken code, output debug statements of everything you can think of. the more data you see of what is happening the easier it is to fix.
2nd Apr 2018, 2:01 PM
John Wells
John Wells - avatar
+ 2
console.log(limit+" "+isPrime+" "+count); at top of your while loop would have shown limit going up others not changing.
2nd Apr 2018, 2:05 PM
John Wells
John Wells - avatar
+ 2
2nd Apr 2018, 2:10 PM
John Wells
John Wells - avatar
+ 2
click on link and it should take you to right place. I had Discord account before linking server and that is all I did.
2nd Apr 2018, 2:26 PM
John Wells
John Wells - avatar
+ 2
I DM did you get
2nd Apr 2018, 2:33 PM
John Wells
John Wells - avatar
+ 1
This is why code layout is so important. I've laid out your code more neatly (and changed nothing else). Can you find the problem now? If not, I can tell you. https://code.sololearn.com/WzPPo5114D15/#js
2nd Apr 2018, 11:09 AM
Emma
+ 1
once isPrime is false it can never become true.
2nd Apr 2018, 1:30 PM
John Wells
John Wells - avatar
+ 1
Sir John please what can I do to be a great coder.. or what can I do to be competent on the average
2nd Apr 2018, 1:53 PM
Sammy
Sammy - avatar
+ 1
The more errors you fix or understand the fixes others give you; The less issues you will have in the future. Practice everything in small pieces at a time. Prove a piece does what you want before expanding it to the next. The more you do the easier it will get.
2nd Apr 2018, 1:57 PM
John Wells
John Wells - avatar
+ 1
Discord is my only social app.
2nd Apr 2018, 2:02 PM
John Wells
John Wells - avatar
+ 1
create account and I'll DM you
2nd Apr 2018, 2:07 PM
John Wells
John Wells - avatar
0
no bro except that I'm dividing by 0 and making the remainder 2 for it to be false I'm confused as the codeplayground isn't responding
2nd Apr 2018, 12:28 PM
Sammy
Sammy - avatar
0
please help me out
2nd Apr 2018, 12:28 PM
Sammy
Sammy - avatar
0
in details pls
2nd Apr 2018, 12:28 PM
Sammy
Sammy - avatar
0
please can you rewrite yours
2nd Apr 2018, 12:36 PM
Sammy
Sammy - avatar
0
Xan please could you help me out
2nd Apr 2018, 1:08 PM
Sammy
Sammy - avatar
0
Sir John please could you explain using a code.. I'm a newbie
2nd Apr 2018, 1:31 PM
Sammy
Sammy - avatar