Please explain this one

for num in range(10, 14):
for i in range(2, num):
if num%i == 1:
print(num)
break

1 Like

for num in range(10, 14):
**for i in range(2, num):
****if num%i == 1:
******print(num)
******break

In the above code nested loop is used .
In the fist line .i.e. β€œfor num in range(10, 14):” β€”> it will start from 10 and end on 13
In the second line .i.e. β€œfor i in range(2, num):” β€”> it will start from 2 and go till num-1
In the third line .i.e " if num%i == 1: " β€”> it means that remainder should be 1
In the fourth line.i.e. " print(num)" β€”> it will provide the o/p which has remainder as 1

So for the first step it will iterate over to 10 .i.e. num = 10 then it will go to second loop i.e. i = 2 . After getting the β€œnum” and β€œi” it will check "if num%i == 1: " if this condition is satisficed then it will print the num or it will move to next " i " .i.e 3 and so on .

2 Likes