C ++ ape's Python note 02-Control Flow

Source: Internet
Author: User

Note: Colon 

If else

If ...:

Indent

Else:

Indent

If Guess = Number:
Print   ' Congratulations, you guessed it. '   # New block starts here
Running = False
Elif Guess < Number:
Print   ' No, it is a little higher than that '   # Another block
# You can do whatever you want in a block...
Else :
Print   ' No, it is a little lower than that '
# You must have guess> number to reach here

 

Switch

No switch. Replace it with if...: Elif...: else :.

 

While

While XX:

Indent

Else:

Indent

While Done = False:
I = I + 1 ;
Print   ' Frame ' , I
Else :
Print   ' The while loop is over. '

For

For element in Arrays:

Indent

Else:

Indent

For I In Range ( 1 , 5 ):
Print I
Else :

Print'The for loop is over'


Break

Terminate the cycle.

Note:If you terminate a for or while loop, no corresponding loop else block will be executed.

 

Continue

The statement following this loop is escaped and enters the next loop.

Note:The continue statement is also valid for the for 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.