+ 1
Could anyone explain me the inner loop, like how its iterating with the outer loop? Thanks!
for num in range(Lower, Upper +1): if num > 1: for i in range (2,num): if num % i ==0: break else: print(num)
2 ответов
+ 4
Dipanjan Basu ,
The code looks like part of a prime finder. You haven't defined L or U, which by the way should be lowercase, and words are better, like lower and upper.
Each time the outer loop increases num, the range of the inner loop increases as it checks all the numbers from 2 to num against num.
+ 3
Dipanjan Basu ,
just to explane what the 2 loops are doing:
> the outer loop generates numbers (using range()) that should be checked if they are prime.
> the inner loop is taking one value from the outer loop at a time. it also generates numbers that are used as divisors for the current value from the inner loop.
if all division are done, the flow will continue with the next number from the outer loop.