Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The for loop
The while loop
Nested loops
break and continue
18. continue with while loops
Summary

Instruction

Good job! Another keyword we can use in loops is continue. While break terminates the entire loop, continue skips the remainder of the current iteration. Take a look:

counter = 0
while counter < 10:
  counter += 1
  if counter == 3: 
    continue
  print('Current value:', counter)

The loop above will execute 10 times, but when the counter value equals 3, the continue keyword will immediately jump to the end of the current iteration.

In this case, the print function will not show anything to the output for that iteration. As a result, we will see 9 lines printed instead of 10 – Current value: 3 will be skipped.

Exercise

The template code you can see shows all even numbers that are less than 100. Modify the template code so that it does not print the even numbers that are less than 100 and are divisible by 6.

Stuck? Here's a hint!

Between the incrementation and the print() function, introduce an if statement with the continue keyword.