Usage of else in loop

name = 'hello'
for x in name:
    print(x)
    if x == 'l':
        break #Exit the for loop
else:
    print("== During the for loop, if there is no break, execute ==")



name = 'hello'
for x in name:
    print(x)
    #if x == 'l':
    # break #Exit the for loop
else:
    print("== During the for loop, if there is no break, execute ==")

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325900466&siteId=291194637