GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — learn-python/src/control_flow/test_break.py at master · kanene/learn-python Expand file tree/ Copy pathtest_break.pyMore file actions 25 lines (18 loc) · 798 Bytes / Copy pathtest_break.pyFile metadata and controls25 lines (18 loc) · 798 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 """BREAK statement @see: https://docs.python.org/3/tutorial/controlflow.html The break statement, like in C, breaks out of the innermost enclosing "for" or "while" loop. """ def test_break_statement(): """BREAK statement""" # Let's terminate the loop in case if we've found the number we need in a range from 0 to 100. number_to_be_found = 42 # This variable will record how many time we've entered the "for" loop. number_of_iterations = 0 for number in range(100): if number == number_to_be_found: # Break here and don't continue the loop. break else: number_of_iterations += 1 # We need to make sure that break statement has terminated the loop once it found the number. assert number_of_iterations == 42 |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |