Python Learning Notes (iii)-Process control (while loop)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.