title |
---|
Loop |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
<Tabs defaultValue="input" values={[ { label: 'Input', value: 'input', }, { label: 'Output', value: 'output', }, ] }>
for i in range(10):
print(i)
0
1
2
3
4
5
6
7
8
9
prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
message = ""
while message != 'quit':
message = input(prompt)
print(message)
- Use a
flag
to do the same:
prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
active = True
while active:
message = input(prompt)
if message == 'quit':
active = False
else:
print(message)
prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
while True:
message = input(prompt)
if message == 'quit':
break
else:
print(message)
continue
takes to the beginging of loop.
<Tabs
defaultValue="input"
values={[
{ label: 'Input', value: 'input', },
{ label: 'Output', value: 'output', },
]
}>
current_num = 0
while current_num < 10:
current_num += 1
if current_num % 2 == 0:
continue
print(current_num) # print odd numbers only
1
3
5
7
9