# How to skip an iteration in a loop if a condition is verified in python ?

Examples of how to skip an iteration in a loop if a condition is verified in python:

## Example with a simple list

In some cases in can be usefull to skip am iteration in a loop if a condition is verfied. To do that a solution is to use "continue"
(see More Control Flow Tools)

````list_of_letters = ['a','b','c','d','e','f']`

`for i in list_of_letters:`
`        if i == 'c':`
`                print('iteration skipped')`
`                continue`
`        else:`
`                print(i)`
```

gives

````a`
`b`
`iteration skipped`
`d`
`e`
`f`
```

## Example with nested lists

Let's consider the following list of tuples:

````list_of_tuples = [('a',[1,6,3]), ('b',[8,4,5]), ('c',[2,9,6])]`

`for i in list_of_tuples:`
`    for j in i:`
`        print(j)`
`    print(i)`
`    print()`
```

gives then

````1`
`6`
`3`
`a`

`8`
`4`
`5`
`b`

`2`
`9`
`6`
`c`
```

Let's skip the second loop if the value 5 is found:

````for i in list_of_tuples:`
`    for j in i:`
`        if j == 5:`
`            continue`
`        else:`
`            print(j)`
`    print(i)`
`    print()`
```

gives

````1`
`6`
`3`
`a`

`8`
`4`
`b`

`2`
`9`
`6`
`c`
```

Another example of how to skip the iteration for both loops if the value 5 is found:

````for i in list_of_tuples:`
`    sc = False`
`    if 5 in i:`
`        sc = True`
`        continue`
`    else:`
`        for j in i: print(j)`
`    if sc: continue`
`    print(i)`
`    print()`
```

gives

````1`
`6`
`3`
`a`

`2`
`9`
`6`
`c`
```