Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Break/Continue in a while Loop
course content

Course Content

Python Loops Tutorial

Break/Continue in a while LoopBreak/Continue in a while Loop

Now, we'll attempt the same task we previously accomplished with the for loop—finding a number in the list and terminating the loop once it's located.

Examine the code below:

How does the code work?


Please be aware that the continue statement skips a block of code within the loop for the current iteration only. Now, let's count the occurrences of 11s in the code using continue.

Examine the code below:

How does the code work?


Halt the loop when encountering a negative value.

  1. Initialize a while loop, employing i to interact with numbers.
  2. Increment the value of i.
  3. Display a message along with the negative element.
  4. Employ break and continue as needed.

Everything was clear?

Section 2. Chapter 5
toggle bottom row