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!"
while continues until some condition is met, then stops. You can also break out of the while loops with the break command.
'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.
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.
^That is more technically correct "Not met." :p
Got it. Thanks.
break lets you skip a snippet of code
Join our real-time social learning platform and learn together with your friends!