Tools, FAQ, Tutorials:
'break' Statement in Repeating Statement Blocks
How to use the "break" statement in a repeating statement block in Python code?
✍: FYIcenter.com
The "break" statement can be used in a repeating statement block like "for" and "while" loops
to terminate the loop immediately.
When a "break" statement is interpreted, Python will terminate execution of the nearest "for" or "while" loop, and skip its optional "else" statement block.
For example:
>>> for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print(str(n)+' equals '+str(x)+' * '+str(n/x)) ... break ... else: ... print(str(n)+' is a prime number') ... 2 is a prime number 3 is a prime number 4 equals 2 * 2.0 5 is a prime number 6 equals 2 * 3.0 7 is a prime number 8 equals 2 * 4.0 9 equals 3 * 3.0
⇒ 'continue' Statement in Repeating Statement Blocks
⇐ 'while ... else' Repeating Statement Blocks
2018-02-28, ∼2714🔥, 0💬
Popular Posts:
How to Build my "sleep" Docker image from the Alpine image? I want the container to sleep for 10 hou...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
What is EPUB 3.0 Metadata "dc:description" Element? EPUB 3.0 Metadata "dc:description" is an optiona...
Where to see some Examples of Invalid JSON Values? Here are some Examples of Invalid JSON Values: 1....
How To Access a Global Variable inside a Function? in PHP? By default, global variables are not acce...