while loop in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

while loop in Python

The below shows a program to print all the prime numbers between an interval. https://code.sololearn.com/ccZc3UjQCPZu I am not understanding how it is able to judge 2 is a prime number as at the starting 2%2=0 and the inner for loop should be exited.

20th May 2019, 10:28 PM
harshit
harshit - avatar
1 Answer
+ 2
When num = 2 we have for i in range(2, 2): Which is an empty range so it's skipped, then the else part is executed and the number is printed.
20th May 2019, 10:37 PM
Diego
Diego - avatar