** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
while
count = 0
while count < 5:
print(count)
# count = count +Same meaning as 1
count += 1
result
0
1
2
3
4
As long as the condition specified by while
is met, it loops within the indent.
break
count = 0
while True:
if count >= 5:
break
print(count)
count += 1
result
0
1
2
3
4
Break out of that loop with break
.
continue
count = 0
while True:
if count >= 5:
break
if count == 2:
count += 1
continue
print(count)
count += 1
result
0
1
3
4
continue
skips the downstream line and enters the next loop.
In this code, when count == 2
, count is not printed and it is in the next loop, so
2 is not displayed as the execution result.
Recommended Posts