4. Python Control Flow

Source: Internet
Author: User
Tags exit in

4-1.python Control Flow

There are three types of control flows:1, sequential structure, 2, branching structure, (IF) 3, cyclic structure; (while,for)

4-2. Branch structure IF

format:If this is the case: Execute this part of the statement elif: Execute this part of the statement else: Execute this part of the statement Example: 4-3. Loop structure while format:The while condition is true: Loop executes the partial statement else: If the condition is false, execute this part of the statement#else部分可以省略 Example: Example:

4-4. Loop structure for

format:For I in Collection :Perform this part else: Execute the section Example: Example: Example: for nested loops "NOTE: The interval in Python is not covered by the end of the header" 4-5.break StatementsBreaks are used to break program execution, which is used to force the loop to stop and exit in a recurrent structure. application of break in the while loop: application of break in the For loop: application of break in a double loop:

4-6.continue statements

the difference between break and continue:The break statement is a force stop execution of the entire loop; The continue statement is the execution of the forced Stop loop, which jumps directly to the next execution;terminate the cycleInstead ofterminate the Loop。 Example:  Example:As you can see from this example, if you want a part to not execute, place that partial output in thebehind the continue., and if you want it to be unaffected, place the output of that part in thethe front of the continue。

4. Python Control Flow

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.