Example use of "continue" statement in Python?

JohnG picture JohnG · Dec 7, 2011 · Viewed 191.3k times · Source

The definition of the continue statement is:

The continue statement continues with the next iteration of the loop.

I can't find any good examples of code.

Could someone suggest some simple cases where continue is necessary?

Answer

Snehal Parmar picture Snehal Parmar · May 5, 2014

Here's a simple example:

for letter in 'Django':    
    if letter == 'D':
        continue
    print("Current Letter: " + letter)

Output will be:

Current Letter: j
Current Letter: a
Current Letter: n
Current Letter: g
Current Letter: o

It continues to the next iteration of the loop.