Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

jberriz

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
  1. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 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
  2. KathrynPeake
    Best Response
    You've already chosen the best response.
    Medals 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
  3. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 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
  4. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    ^That is more technically correct "Not met." :p

    • one year ago
  5. jberriz
    Best Response
    You've already chosen the best response.
    Medals 0

    Got it. Thanks.

    • one year ago
  6. Krishnadas
    Best Response
    You've already chosen the best response.
    Medals 0

    break lets you skip a snippet of code

    • one year ago
    • Attachments:

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.