반응형
count = 0
while True: # this condition cannot possibly be false
print(count)
count += 1
if count >= 5:
break # exit loop if count >= 5
zoo = ["lion", 'tiger', 'elephant']
while True: # this condition cannot possibly be false
animal = zoo.pop(2) # extract one element from the list end
print(animal)
if animal is 'elephant':
break # exit loop
산출물 (Output)
0
1
2
3
4
elephant
* An infinite loop is a loop that never exits.
If the loop condition happens to always be true, such a loop becomes infinite.
The "break" keyword is used to exit the current loop.
<br><br>
Exit the loop correctly using "break".
<br>
반응형
'Python 배우기' 카테고리의 다른 글
functions.py (0) | 2016.03.10 |
---|---|
continue_keyword.py (0) | 2016.03.10 |
while_loop.py (0) | 2016.03.10 |
for_string.py (0) | 2016.03.09 |
for_loop.py (0) | 2016.03.09 |
댓글