0% found this document useful (0 votes)
3 views

Break & Continue Notes

The document explains jump statements in Python, specifically the 'break' and 'continue' statements used in loops. The 'break' statement terminates the current loop, while the 'continue' statement skips the current iteration and moves to the next one. Examples illustrate how these statements function within 'for' and 'while' loops.

Uploaded by

Waseem Mohammed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Break & Continue Notes

The document explains jump statements in Python, specifically the 'break' and 'continue' statements used in loops. The 'break' statement terminates the current loop, while the 'continue' statement skips the current iteration and moves to the next one. Examples illustrate how these statements function within 'for' and 'while' loops.

Uploaded by

Waseem Mohammed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Jump Statements in Python

(break & continue)


Pre-Test
• What do you mean by looping in python?
• Which are the 2 types of looping constructs in python?
Learning Objective
• To explore the concept of jump statements in Python
programming.
Jump Statements in Python
• Looping helps us to program and repeat tasks efficiently.
• In certain situations, when some particular condition occurs,
we may want to come out of the loop forever or skip some
statements before continuing further in the loop.
• The above requirements can be fulfilled by Jump statements in
python.
• 2 types of jump statements in python are:
 break
 continue
break Statement in Python
• The break statement terminates the current loop,i.e., the loop in
which it appears, and resumes execution at the next statement
immediately after the end of the loop.
• If break statement is inside a nested loop(loop inside another loop),
break will terminate the innermost loop.
• Example for illustrating break statement in for loop:
for i in range(9): Output 0
if i > 3: 1
break 2
print(i) 3
break Statement in for loop
• Another Example for illustrating break statement
num=0
for i in range(10):
num=num+1
if num==5:
break
print(“Num is”,num)
• Example
for i in 'PYTHON’: Output
if i==‘H’: P
break Y
print(i) T
break Statement in while loop
• Program to find sum of all positive numbers entered by user. When
the user enters a negative number ,it stops taking any more
numbers from them and displays the sum.
sum=0
While True:
n=int(input(“Enter the numbers to find the sum”))
if n<0:
break
sum=sum+n
print(“Sum is”,sum)
continue Statement in Python
• Continue statements takes the control to next iteration skipping the
execution of statements for current iteration.
• Here, loop does not terminate, but continues on next iteration.
• Example:
for i in ‘PYTHON’: Output
if i==‘H’: P
continue Y
print(i) T
O
N
5
continue Statement in Python
• #Prints values from 0 to 6 except 3
num = 0
for num in range(6):
Output
num = num + 1
Num has value 1
if num == 3:
Num has value 2
continue Num has value 4
print('Num has value ‘,num) Num has value 5
print('End of loop') Num has value 6
End of loop
Activity

Find the output :

a) for i in range(9): b) for i in range(9):


if i==3: if i==3:
break continue
print(i) print(i)
Activity Contd….

c) i=0 d) i=0
while i <10: while i <10:
i=i+1 i=i+1
if i==5: if i==5:
break break
print(i,end='') print(i, end='')
Let’s Recap…..
• Jump statements in python
• break
• continue

You might also like