我有一个代码或停止循环,我不知道该怎么做才能停止

时间:2019-05-09 13:09:33

标签: python python-3.x

我有一个代码或停止循环,我不知道该怎么做

ciao = "revoir bye see you"
ciao = ciao.lower().split()
quests = "revoir mam bak kio"
quests = quests.lower().split()
while 1: 
    for i in range(len(quests)):
        if quests[i] in ciao:
            break
        print('khvb')

1 个答案:

答案 0 :(得分:2)

您的问题不清楚。

中断只会停止for循环,如果您希望它停止while循环,则可以考虑以下内容:

ciao = "revoir bye see you"
ciao = ciao.lower().split()
quests = "revoir mam bak kio"
quests = quests.lower().split()
should_continue = True
while should_continue: 
    for i in range(len(quests)):
        if quests[i] in ciao:
            should_continue = False
            break
        print('khvb')
``