This program determines the number of prime numbers up to 30
for i in range(2,30):
for in range(2, i):
if i%s == 0:
break
else:
print(i)
I don't understand why if and else have different indents.
If else is indented the same as if, I understand that the result is wrong.
The 4.4.break and continue statements, and else Claims on Loops From that perspective, if you double-check the behavior of the code you posted, you will be able to confirm that it is working as it should. When I searched in English, I found a lot of arguments like "Why else
corresponds to the else
statement, but not to the for
statement. The Python else
statement (such as the else
statement) can have a else
clause until the end of the loop.
else
", but it seems to end up as "it seems natural once you get used to it."
© 2024 OneMinuteCode. All rights reserved.