Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Can someone help me understand how this code works? I am not familiar with how the break command works.
i = 2
while(i < 100):
j = 2
while(j <= (i/j)):
if not(i%j): break
j = j + 1
if (j > i/j) : print i, " is prime"
i = i + 1
print "Good bye!"
 one year ago
 one year ago
Can someone help me understand how this code works? I am not familiar with how the break command works. i = 2 while(i < 100): j = 2 while(j <= (i/j)): if not(i%j): break j = j + 1 if (j > i/j) : print i, " is prime" i = i + 1 print "Good bye!"
 one year ago
 one year ago

This Question is Closed

KonradZuseBest ResponseYou've already chosen the best response.0
while continues until some condition is met, then stops. You can also break out of the while loops with the break command.
 one year ago

KathrynPeakeBest ResponseYou've already chosen the best response.0
'break' jumps you out of the while(j ... loop. If j is a factor of i, then i is not prime, so you don't need to test any further values of j.
 one year ago

rsmith6559Best ResponseYou've already chosen the best response.2
while continues until some condition is NOT met, then stops. If the condition returns true, the code block is executed. If the condition returns false, the code block is skipped.
 one year ago

KonradZuseBest ResponseYou've already chosen the best response.0
^That is more technically correct "Not met." :p
 one year ago

KrishnadasBest ResponseYou've already chosen the best response.0
break lets you skip a snippet of code
 one year ago
See more questions >>>
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.