CONTINUE STATEMENT IN PYTHON

in #code4 years ago

This is a simple basic conceptual program on how continue statement works in python. In the code below we can see that from 1 to 50, the numbers that are divisible by both 4 and 5 (i.e. 20 and 40) are not printed. The rest numbers are printed. Remember for the 'and' logical operator both statements must be true. The continue statement is used to skip the rest of the code inside the loop and is used to go back to beginning of the loop to begin the next iteration. That meant to say that continue won't execute the statement whose condition is true.

for i in range(1,50):
    if i%4==0 and i%5==0:
        continue
        
    print(i) 

If you run the above code, you can see the following output:


Screenshot_1.png

You can run this code online here.

Sort:  

Upvoted by GITPLAIT!

We have a curation trial on Hive.vote. you can earn a passive income by delegating to @gitplait
We share 80 % of the curation rewards with the delegators.


To delegate, use the links or adjust 10HIVE, 20HIVE, 50HIVE, 100HIVE, 200HIVE, 500HIVE, 1,000HIVE, 10,000HIVE, 100,000HIVE


Join the Community and chat with us on Discord Let’s solve problems & build together.