Repository navigation
Expand file tree
/
Copy path051-Break-Statement.py
More file actions
62 lines (50 loc) · 2.13 KB
/
Copy path051-Break-Statement.py
File metadata and controls
62 lines (50 loc) · 2.13 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
===============================================================================
Break Statement
===============================================================================
Program Description:
--------------------
This program demonstrates the use of the break statement in Python.
The break statement is used to terminate a loop immediately when a
specified condition becomes True. After the break statement is executed,
the control comes out of the loop.
Syntax:
break
Author : Shaik Mahaboob Basha
Repository : 13-Python
File Name : 51-Break-Statement.py
===============================================================================
"""
# -----------------------------------------------------------------------------
# Displaying a heading.
# -----------------------------------------------------------------------------
print("Break Statement Example")
# Output: Break Statement Example
# -----------------------------------------------------------------------------
# Using a for loop to display numbers.
# -----------------------------------------------------------------------------
for number in range(1, 11):
# -------------------------------------------------------------------------
# Checking whether the current number is equal to 6.
# -------------------------------------------------------------------------
if number == 6:
# ---------------------------------------------------------------------
# Terminating the loop when the condition becomes True.
# ---------------------------------------------------------------------
break
# -------------------------------------------------------------------------
# Displaying the current number.
# -------------------------------------------------------------------------
print(number)
# Output:
# 1
# 2
# 3
# 4
# 5
# -----------------------------------------------------------------------------
# Displaying a message after the loop.
# -----------------------------------------------------------------------------
print("Program Completed.")
# Output:
# Program Completed.