for 嵌套
for i in range(1, 10):
for j in range(1, i+1):
print(f'{i} x {j} = {i * j}',end=' ')
print()while嵌套
i = 1
while i < 10:
j = 1
while j < i + 1:
print(f'{i} x {j} = {i * j}', end=' ')
j += 1
print()
i += 1while for嵌套
i = 1
while i < 10:
for j in range(1, i + 1):
print(f'{i} x {j} = {i * j}', end=' ')
print()
i += 1退出、break、continue
x = True
while x:
s = input('input:')
if s == 'e':
x = False
print('exit , else 会运行')
elif s == 'ee':
print('exit , else 不会运行')
break
elif s == 'c':
continue # 不做任何事情
print('print:', s)
else:
# beak时 不会执行
print('hello')
评论