Question Detail

COS 102 6 lecture note; fundamentals of programming Objective Question

Question

Which of the following accurately describes a difference between break and continue statements in Python loops?
Options
A <code>break</code> is used in <code>for</code> loops, while <code>continue</code> is used in <code>while</code> loops.
B <code>break</code> terminates the entire loop, while <code>continue</code> skips only the current iteration.
Correct Answer
C <code>break</code> causes early execution of the next iteration, while <code>continue</code> causes early termination of the loop.
D <code>break</code> and <code>continue</code> have identical functionalities and can be used interchangeably.
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 104 clearly states: 'break' terminates the execution of remaining iteration of the loop. 'continue' terminates only the current iteration of the loop. Also, 'break' stops the continuation of loop. 'continue' do not stops the continuation of loop, it only stops the current iteration.

Hint

One exits the loop completely, the other just skips to the next cycle.

Question Info