4. Introduction to Python-Loop

cycle

for statement

  for element variable in sequence:

    Execute statement

  range (start, end, step) generate sequence

#Maximum 
a = [ 1423 , 2451 , 21 , 475 , 1668 , 68 ] 

maxx = a [ 0 ] 

for x in range ( 0 , len (a) -1 ):
     if a [x] <= a [x + 1 ]: 
        maxx = a [x + 1 ] 
        
print ( " Result: " , maxx)

while statement

  while judgment condition:

    Execute statement

continue和break

  continue: skip this loop and start the next loop

  break: break out of this loop

 

Guess you like

Origin www.cnblogs.com/Just-a-calm-programmer/p/12667455.html