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