Turn Messy Text into Structured Insights With AI. Join Greg Live:Β Dec 4th, 2024
Leverage
Glossary

Continue

Use of continue in Python loops

Python continue is a keyword that will tell your code to move to the next item in a loop. It will skip all other code that comes after your continue statement. This is heavily used with for and while loops in python.

for i in range(10):
  if i == 3:
    continue
  print (i)

Let’s talk about the example above. Imagine that you’re looping through the range(10) and you want to print each number except for 3. You can have a conditional statement to look for the number 3. If you find it, then tell python to continue on to the next item in your list.

Keep in mind that if you have nested loops, continue will only skip the item within the first loop it is placed in.

Let’s take a look at a python continue code sample.

Link to code

On this page

No Headings