티스토리 뷰
1. while 문
- 표현식이 참인 동안 실행식을 반복
i = 0
total = 0
while i < 100:
i = i + 1
total = total + i
print(total)- continue
- continue 키워드를 통해 다음 loop로 넘어 갈 수 있음
i = 0
total = 0
while i < 100:
i = i + 1
if i % 2 == 0:
continue
total = total + i
print(total)
- break
- break 키워드를 통해 loop를 탈출
import random
limit = 0.8
s = 0
while 1:
tmp = random.random()
if tmp > limit:
break
s = s + tmp
print(s)
Reference: https://docs.python.org/ko/3.6/reference/compound_stmts.html#while
'Computer Language > Python' 카테고리의 다른 글
| 모듈(Modules) (0) | 2018.07.30 |
|---|---|
| 클래스(Classes) (0) | 2018.07.21 |
| 예외 처리(Handling Exceptions) (0) | 2018.07.18 |
| 튜플과 시퀀스(Tuples and Sequences) (0) | 2018.07.17 |
| 딕셔러니(Dictionaries) (0) | 2018.07.15 |
댓글