CONTINUE in Python WHILE Loops

🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ CONTINUE in Python WHILE Loops

The Python CONTINUE statement, on the other hand, will immediately terminate the current loop iteration. The execution jumps to the top of the loop and re-evaluate the expression, to determine whether the loop will execute again with the next iteration, or if it will terminate and proceed to the first statement following the loop.

     while expression is True:
         statement_1
         statement_2
         if condition is True:
             continue
         ...
         statement_3
         ...
     following_statement

Let’s have a look at the same example you have seen, in the break statement. But, instead of break in Python, you will now use the CONTINUE statement. Continue is also a control statement in Python, but the only difference is that it will only skip the current iteration in the loop, continues with the next iteration – then executes the rest of the iterations anyway, until the while condition becomes False

     colours = ['red', 'green', 'blue', 'yellow']
     
     while colours:
         colour = colours.pop()
         if colour == 'blue': continue
         print(colour)

In the above example, as soon as the loop encounters the item ‘blue’, it will enter the if statement block, where the continue statement will skip the current item in the loop, then continues to the next iteration, with the item yellow. This, loop will repeat until it reaches the lat item of the sequence, and result in printing out ‘red’, ‘green’ and ‘yellow’ – since blue has been skipped over.

Let’s play this video, stick around and watch until the end of this video! 👍🏻

– Digital Academy™ 🎓

***

☞ WATCH NEXT:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho

☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw

📖 Blog: http://digital.academy.free.fr/blog/

📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners

🛒 Shopping and Discounts: http://digital.academy.free.fr/store/

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡
http://digital.academy.free.fr/
https://twitter.com/DigitalAcademyy
https://www.facebook.com/digitalacademyfr
https://www.instagram.com/digital_academy_fr/
https://www.youtube.com/c/DigitalAcademyOnline

♡ SUPPORT US ♡
http://digital.academy.free.fr/join
http://digital.academy.free.fr/donate
http://digital.academy.free.fr/subscribe
https://www.patreon.com/digital_academy
https://www.buymeacoffee.com/digital_academy

***

Copy link
Powered by Social Snap