7.while circulation, exit, contiune, break, the cycle of death


while loop
COUNT = 0
while COUNT <100:
Print ( "I want a baby")
COUNT + =. 1

Number mating
COUNT = 0
while COUNT <100:
IF COUNT% 2 == 0:
Print ( "I want a baby" , COUNT)
COUNT +. 1 =

find odd
COUNT = 0
the while COUNT <100:
IF COUNT == 2%. 1:
Print ( "I want a baby", COUNT)
COUNT = +. 1



Import Random
n-the random.randint = (1,10 )
Print (n-)
COUNT = 0
the while COUNT <. 5:
user_guess = int (iNPUT ( "Please enter:"))
IF user_guess> n-:
Print ( "too big")
elif user_guess <n-:
Print ( "too small ")
the else:
Print ("niubility")
exit () # terminate the entire program, print (count) does not print
COUNT + =. 1
Print (COUNT)

Import Random
n-the random.randint = (1,10)
Print (n-)
COUNT = 0
the while COUNT <. 5:
user_guess = int (INPUT ( "Please enter:"))
IF user_guess> n-:
Print ( "too big")
elif user_guess <n-:
Print ( "too small")
the else:
Print ( "niubility")
BREAK # terminate the entire cycle, print ( count) printing
COUNT + =. 1
Print (count)

COUNT = 0
the while COUNT <100:
COUNT + =. 1
iF COUNT> 10 and COUNT <20 is:
continue # terminates when the cycle continues for the next cycle
Print (count)

the else: # when loop normal end condition is not satisfied, the execution
print ( "Dsds")

break continue and so need to use the loop statement. The for loop can be


an infinite loop
deadloop
the while to true:
  Print ( "you are a sucker you?")

Guess you like

Origin www.cnblogs.com/xh716/p/11548486.html