Page 199 - AI_Ver_3.0_class_11
P. 199
Program 23: To demonstrate the use of the break statement using for loop
for number in range(0, 10):
if(number == 5):
break
print('Number is:', number)
print('The loop exits!!!')
Output:
Number is: 0
Number is: 1
Number is: 2
Number is: 3
Number is: 4
The loop exits!!!
The continue Statement
The continue statement is used inside loops. When a continue statement is encountered inside a loop, then the control
of the program jumps to the beginning of the loop for next iteration, skipping the execution of rest of the statements of
the loop for the current iteration.
The syntax of the continue statement is as follows:
#loop statements
continue
#the code to be skipped
Program 24: To demonstrate the use of the continue statement
for i in range(1, 6):
if i == 3:
continue # Skip the rest of the loop body for i == 3
print("Iteration:", i)
Output:
Iteration: 1
Iteration: 2
Iteration: 4
Iteration: 5
#Digital Literacy
Video Session
Watch the video: Python Lists, Tuples And Dictionaries - 10 | Python For Beginners |
Python Tutorial | Simplilearn - https://www.youtube.com/watch?v=fXRxHrDhQuI
Python Programming 197

