while循环。for循环

1、while循环

  基本循环格式  

while 条件 :
        #  循环体

        # 如果条件为真,那么循环体则执行
        # 如果条件为假,那么循环体不执行

  break:退出本层循环。

  continue:退出本次循环,进入下一次循环。

  利用标志位tag控制循环。

复制代码
tag=True
while tag:
    username=input('username: ')
    password=input('password: ')
    if username == 'egon' and password == '123':
        while tag:
            cmd=input('>>: ')
            if cmd == 'q':
                tag=False
                continue
            print('------>%s' %cmd)
复制代码

2、for循环

 双层嵌套打出99乘法表

for i in range(1,10):
    for j in range(1,i+1):
        print('%s*%s=%s' %(i,j,i*j),end=' ')
    print()
原文地址:https://www.cnblogs.com/1204guo/p/6959426.html