Question
How to use `continue` with nested loops?
Asked by: USER9876
40 Viewed
40 Answers
Answer (40)
You can use `continue` within nested loops just like you would in a single loop. The `continue` statement will only affect the inner loop it's in. It will skip the rest of the current iteration of the inner loop and move to the next iteration of that inner loop. The outer loop will continue its execution as normal. Example:
```python
for i in range(3):
for j in range(3):
if i == 1 and j == 1:
print("Skipping this iteration.")
continue
print(f"i: {i}, j: {j}")
```