Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- web
- DS
- Algorithm
- Linux
- DATAPATH
- system
- javascript
- Pipelining
- DoM
- php
- react
- data structure
- MIPS
- while
- mysql
- function
- html
- control
- Class
- for
- architecture
- computer
- CSS
- github
- XML
- MacOS
- Java
- instruction
- python
- DB
Archives
- Today
- Total
YYYEJI
[Python] 반복문 (while문) 본문
728x90

반복문이란?
특정 조건을 만족할 때 같은 동작을 계속해서 반복하고자 할 때 사용합니다.
Ex) for문, while문 etc . . .
while <조건문>:
반복할 문장
while문은 조건문이 참일 때 아래 코드를 수행합니다.
Note) python에서 0은 false, 1은 true.
아래 코드는 i가 10보다 작거나 같으면 아래 문장을 수행하게 됩니다.
i = 0
while i<=10:
print(i)
i += 1

아래 코드는 1자체가 true이기 때문에 아래 문장이 수행됩니다.
while 1:
print("Hello World")
break

True를 직접적으로 넣어주셔도 괜찮습니다.
while True:
print("Hello World")
break

잘못해서 무한루프가 걸린 경우 !
Control + c
를 눌러주시면 빠져나올 수 있습니다.
◡̈
'Python' 카테고리의 다른 글
[Python] 튜플(Tuple) 정리 (0) | 2022.10.06 |
---|---|
[Python] for문과 while문의 차이점 (2) | 2022.09.29 |
[MacOS] FileNotFoundError: [Errno 2] No such file or directory: 'xxxx.txt' (0) | 2022.09.28 |
[Python] find, startswith, endswith 함수 (0) | 2022.09.26 |
[Python] Enumerate 함수 (0) | 2022.09.26 |