A community for students.
Here's the question you clicked on:
 0 viewing
jberriz
 3 years 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!"
jberriz
 3 years 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!"

This Question is Closed

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

KathrynPeake
 3 years ago
Best 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.

rsmith6559
 3 years ago
Best ResponseYou've already chosen the best response.2while 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.

KonradZuse
 3 years ago
Best ResponseYou've already chosen the best response.0^That is more technically correct "Not met." :p

Krishnadas
 3 years ago
Best ResponseYou've already chosen the best response.0break lets you skip a snippet of code
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.