Python中break和continue区别

来自YTYZX有图有真相的百科
跳转至: 导航搜索
1. continue
for i in range(10):
    print("-----%d-----" %i)
    for j in range(10):
        if j > 5 and j <= 8:
            print(f'此处输出大于5且小于等于8的数字{j}')
            continue
    print(j)


2. break
for i in range(10):
    print("-----%d-----" %i)
    for j in range(10):
        if j > 5 and j <= 8:
            print(f'此处输出大于5且小于等于8的数字{j}')
            continue
    print(j)