Python Break
Python Break
Python Java JavaScript SQL C++ HTML CSS React
← prev next →
The break is commonly used in the cases where we need to break the loop for a given
condition. The syntax of the break statement in Python is given below.
Syntax:
#loop statements
break;
Output:
Item matched
Found at location 2
In the above example, a list is iterated using a for loop. When the item is matched with
value 4, the break statement is executed, and the loop terminates. Then the count is
printed by locating the item.
Output:
p
y
t
h
When the character is found in the list of characters, break starts executing, and
iterating stops immediately. Then the next line of the print statement is printed.
Output:
It is the same as the above programs. The while loop is initialised to True, which is an
infinite loop. When the value is 10 and the condition becomes true, the break
statement will be executed and jump to the later print statement by terminating the
while loop.
Output:
2 X 1 = 2
2 X 2 = 4
2 X 3 = 6
2 X 4 = 8
2 X 5 = 10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
2 X 10 = 20
Do you want to continue printing the table? Press 0 for no: 1
3 X 1 = 3
3 X 2 = 6
3 X 3 = 9
3 X 4 = 12
3 X 5 = 15
3 X 6 = 18
3 X 7 = 21
3 X 8 = 24
3 X 9 = 27
3 X 10 = 30
Do you want to continue printing the table? Press 0 for no: 0
Exiting the program...
Program finished successfully.
There are two nested loops in the above program. Inner loop and outer loop The inner
loop is responsible for printing the multiplication table, whereas the outer loop is
responsible for incrementing the n value. When the inner loop completes execution,
the user will have to continue printing. When 0 is entered, the break statement finally
executes, and the nested loop is terminated.
← prev next →
Related Posts
Python Loops
The following loops are available in Python to fulfil the looping needs. Python
offers 3 choices for running the loops. The basic functionality of all the
techniques is the same, although the syntax and the amount of time required
for checking the condition differ. We can run...
6 min read
4 min read
Python If else
Python If-else statements Decision making is the most important aspect of
almost all the programming languages. As the name implies, decision making
allows us to run a particular block of code for a particular decision. Here, the
decisions are made on the validity of the particular...
6 min read
Python Continue
Python continue Statement Python continue keyword is used to skip the
remaining statements of the current loop and go to the iteration. In Python,
loops repeat processes on their own in an efficient way. However, there might be
occasions when we wish to leave the...
3 min read
9 min read
Python Pass
Statement In this tutorial, we will learn more about past statements. It is
interpreted as a placeholder for future functions, classes, loops, and other
operations. What is Python's Pass Statement? The pass statement is also
known as the null statement. The Python mediator doesn't overlook a
Remark,...
2 min read
Python Java
Javascript HTML
Database PHP
C++ React
B.Tech / MCA
Data
DBMS
Structures
Operating
DAA
System
Computer Compiler
Network Design
Computer Discrete
Organization Mathematics
Ethical Computer
Hacking Graphics
Web Software
Technology Engineering
Cyber
Automata
Security
C C++
Programming
Java .Net
Python Programs
Control Data
System Warehouse
Preparation
Aptitude Reasoning
Verbal Interview
Ability Questions
Company
Questions