본문 바로가기
Python 배우기

while_loop.py

by 노화방지 Anti-aging Hairstyle 2016. 3. 10.
반응형
square = 1

while square <= 9:
print(square) # This code is executed 10 times
square += 1 # This code is executed 10 times

print("Finished") # This code is executed once

square = 1
number = 1

while number <= 9: # Print all squares from 0 to 99 (1, 4, ... , 81).

square = number ** 2
print(square)
number = number+1

산출물 (Output)

1
2
3
4
5
6
7
8
9
Finished
1
4
9
16
25
36
49
64
81




* A "while" loop is similar to an "if" statement: it executes some code if some condition is true.
The key difference is that it will continue to execute indented code for as long as the condition is true.



반응형

'Python 배우기' 카테고리의 다른 글

continue_keyword.py  (0) 2016.03.10
break_keyword.py  (0) 2016.03.10
for_string.py  (0) 2016.03.09
for_loop.py  (0) 2016.03.09
else_elif.py  (0) 2016.03.09

댓글