Here's the question you clicked on:

55 members online
  • 0 replying
  • 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!"

  • This Question is Closed
  1. KonradZuse
    • 3 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
    • 3 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
    • 3 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
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

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

    Got it. Thanks.

  6. Krishnadas
    • 3 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.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy