while, for loop structure _python

A basic example of the while loop:

Example 1: determining whether greater than 50

 

 Example 2: Print on demand multiplication formulas

 

 Example 3: infinite loop

while True:
  print (“true”)

 

Two, for circulation

1, the common range for usage cycle:

  for i in (0,3,4,5,7,40): # include all
  for i in range (0,10): #range method 0-9, the last is not included
  for i in range (10): # default starting from 0

2, Example 1: Find the odd

 

 Three, while, for the three key words cycle may

break、continue、exit

break: ends the cycle

continue: the end of this cycle, the next cycle continues

exit: Exit the program

Guess you like

Origin www.cnblogs.com/chenxiaozan/p/12088058.html