A memo on how to write a while statement in python.
python
initial value
while condition:
processing
Step
--Unlike the for statement, the initial value is defined outside the while statement. --Add ":" after the while statement (not ";") --Indent (TAB key) in the while statement --No need for ";" after processing or step
▼ Repeat processing 5 times from initial value 5 to 1
python
i=5;
while i>0:
print(i)
i -= 1
//output
5
4
3
2
1
The conditional expression becomes true and the process is repeated.
python
i=5;
while i>0:
print(i)
Since the value does not change in while, it repeats forever.
python
i=5;
while i>0:
print(i)
i-=1
Recommended Posts