Loops in Python

  1. while
    1 n = 0
    2 while n < 5:
    3     print(n)
    4     n+=1
    5 else:  6 print("End of loop" ) 7

    Note: else means to execute the following statement when the condition is not satisfied

  2. for
    for i in range(10 ):
         print (i)
     else :
         print ( " End of loop " )

    Note: else executes the following statement after i traversal is completed

  3. The break statement jumps out of the current loop (referring to a while or for); continue ends the loop (a step in a loop)

Guess you like

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