Python Programming - Loops - Discussion
Discussion Forum : Loops - General Questions (Q.No. 24)
24.
In Python, what is the purpose of the
break
statement in a loop?
Answer: Option
Explanation:
The
break
statement is used to exit a loop prematurely, regardless of the loop's condition.
Here's an example of using the break
statement in a loop:
for i in range(1, 6):
if i == 3:
break
print(i)
In this example, when the value of i
becomes 3, the break
statement is executed, causing the loop to terminate prematurely. As a result, only the numbers 1 and 2 are printed before the loop is exited.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers