A community for students.
Here's the question you clicked on:
 0 viewing
 3 years ago
I wrote code to calculate the 1000th prime number: http://dpaste.com/hold/640512/ . It works, but upon reviewing, I realized I do not know why. Specifically, the function that's determines primeness at line 20 is not in the "while loop" (lines 2329). What is causing or commanding "x + 2" in lines 25 or 29 to be fed back into the function at line 20? It also works if I put the function in after line 29 as a recursion http://dpaste.com/hold/640514/ . Would appreciate if someone could explain the mechanics of what's going on. Thanks a lot. I wrote code to calculate the 1000th prime number: http://dpaste.com/hold/640512/ . It works, but upon reviewing, I realized I do not know why. Specifically, the function that's determines primeness at line 20 is not in the "while loop" (lines 2329). What is causing or commanding "x + 2" in lines 25 or 29 to be fed back into the function at line 20? It also works if I put the function in after line 29 as a recursion http://dpaste.com/hold/640514/ . Would appreciate if someone could explain the mechanics of what's going on. Thanks a lot. @MIT 6.00 Intro Co…
 3 years ago
I wrote code to calculate the 1000th prime number: http://dpaste.com/hold/640512/ . It works, but upon reviewing, I realized I do not know why. Specifically, the function that's determines primeness at line 20 is not in the "while loop" (lines 2329). What is causing or commanding "x + 2" in lines 25 or 29 to be fed back into the function at line 20? It also works if I put the function in after line 29 as a recursion http://dpaste.com/hold/640514/ . Would appreciate if someone could explain the mechanics of what's going on. Thanks a lot. I wrote code to calculate the 1000th prime number: http://dpaste.com/hold/640512/ . It works, but upon reviewing, I realized I do not know why. Specifically, the function that's determines primeness at line 20 is not in the "while loop" (lines 2329). What is causing or commanding "x + 2" in lines 25 or 29 to be fed back into the function at line 20? It also works if I put the function in after line 29 as a recursion http://dpaste.com/hold/640514/ . Would appreciate if someone could explain the mechanics of what's going on. Thanks a lot. @MIT 6.00 Intro Co…

This Question is Closed

seanlerner
 3 years ago
Best ResponseYou've already chosen the best response.1your prime test function is in the while loop on line 24 and 26. As for what causes your function to iterate, it is because you are using a while loop which will do whatever is in it while a condition is or is not met... does that make sense?

afpratt
 3 years ago
Best ResponseYou've already chosen the best response.0Yeah, that does make sense, thanks a lot. I was thinking about lines 24 and 26 as checking the result of 20, but now I see what's going on.

afpratt
 3 years ago
Best ResponseYou've already chosen the best response.0Further in view of this explanation, I see that the function at line 20 is superfluous, since all the action is taking place in the while loop. I deleted line 20 and it returns the correct answer.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.