The python while and for loops, break and continue

Cycle is performed repeatedly inside the loop body code

1.while first need to define a counter, code examples are as follows:

View Results:

2.for loop counter need not be defined, the direct write cycle times range (n), the following code is an example:

View Results:

 3.break: encounters a break in the loop body, the immediate end of the cycle, code examples are as follows:

The results are as follows: when it comes to break, no matter how much the counter, immediately end the cycle, it is only done once

4.continue: When faced continue, the end of the cycle, re-circulating, code examples are as follows:

The results are as follows:

 

Guess you like

Origin www.cnblogs.com/guangjiao/p/11470078.html