Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
java
c++

What is continue in a while loop?

Anusheh Zohair Mustafeez

Often, when working with loops, one reaches a point where they need to skip the remaining body of the loop for one iteration. In such a situation, the continue statement comes in handy.

The continue statement breaks a single iteration of a loop (if a certain event takes place) and continues execution from the next iteration in the loop. This is explained in the diagram below:

Example

In this shot, we will look at the continue statement in the context of a while loop. Below, the code snippet demonstrates how the continue statement works in Python, C++, and Java. Notice how all multiples of 3 are not printed due to the use of the continue statement.

number = 0
while number < 10:
    number = number + 1
    if number % 3 == 0:
        continue
    print(number)

RELATED TAGS

python
java
c++

CONTRIBUTOR

Anusheh Zohair Mustafeez
RELATED COURSES

View all Courses

Keep Exploring