Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

jberriz

  • 2 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
  1. KonradZuse
    • 2 years ago
    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.

  2. KathrynPeake
    • 2 years ago
    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.

  3. rsmith6559
    • 2 years ago
    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.

  4. KonradZuse
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

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

    Got it. Thanks.

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

    break lets you skip a snippet of code

  7. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.