While loop:
The while loop in the Python process control until the expression becomes false to end. Expression is a logical expression that must return a true or false
The syntax is as follows:
While expression:
Statement (s) #请注意while循环也是要遵循代码缩进原则的
While followed by true condition:
print ' #始终为true, will go into the dead loop, printing prints all the time. , no practical significance.
Then, when we design a Python program, we set a condition that terminates the program, rather than just CTRL + C to terminate the program.
Here's a look at the example:
1 #Coding:utf-82 Import Time3 " "4 While True:5 print "Enjoy youself!" #会进入死循环, only manually press CTRL + C to end6 x = raw_input ("Please input somting to quit the program!")7 if x = = "Q": #添加此条件后, the program ends only if the user enters a value of Q8 Break9 " "Ten Onex=""#string AA = str ()#string -b =Int () -c =float () theD = [] -E = {} - Printtype (x), ID (x) - Printtype (a), ID (a) + Printtype (b), id (b) - Printtype (c), ID (c) + Printtype (d), id (d) A Printtype (e), ID (e) at -Time.sleep (3) - - - whilex!="Q":#x=q is False, x! It's true when you =q . - Print "Enjoy youself!" inx = Raw_input ("Please input somting for quit The program:") - if notX:#x is empty (pressing the ENTER key directly will also end), but it is also false to Break + ifx = ="C": - Continue the Print "One more time*****************" * Else:#when a condition fails such as input q), perform else $ Print "End ... .."
Python Learning Notes (iii)-Process control (while loop)