🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ Infinite WHILE Loops in Python
Suppose you write a while loop that, theoretically, never ends. Sounds weird, right?!
Well, that kind of loop, also known as infinite loop in Python, might be very useful in client / server programming, where the server needs to run continuously so that the client can communicate with it - as and when required.
As you may have understood, an infinite while loop in Python executes infinite times, which means: theoretically, the execution never stops. This may come as a surprise, but it has its own advantages - and its disadvantages, as well. Therefore, you must use it with caution, because of the possibility that this condition never resolves to a False value - and may never exit this infinite loop in Python.
Let's have a look at a more practical example. This program will run infinite iterations, unless you press Ctrl+C, or put a break control statement in the loop. The condition within the while statement must eventually become False. Otherwise, the loop will execute forever - creating an infinite loop!
while True:
print('Press Ctrl+C to stop me!')
Fortunately, you can safely implement an infinite loop in your program, using the break control statement that you have seen little bit earlier. This way, as soon as the condition is met, this break keyword will immediately interrupt the current iteration, exit the infinite loop, and proceed with the next statements - outside of the loop.
while True:
name = input('Enter name:')
if name == 'stop': break
print('Hello', name)
OUTPUT:
Enter name:Alicia
Hello Alicia
Enter name:Bob
Hello Bob
Enter name:stop
Let's play this video, stick around and watch until the end of this video! 👍🏻
Digital Academy™ 🎓
***
☞ WATCH NEXT:
○ Data Types in Python - • DATA TYPES in Python (Numbers, Strings, Li...
○ Operators in Python - • OPERATORS in Python (Arithmetic, Assignmen...
○ IF Statements in Python - • CONDITIONAL Statements in Python (IF, ELIF...
○ FOR Loops in Python - • FOR Loop in Python (Syntax, Break, Continu...
📖 Blog: http://digital.academy.free.fr/blog
📖 [FULL Course] HOW TO Learn Python? Python Tutorial for Beginners: • 🐍 Python 101: Learn Python Basics for Abso...
📖 [PLAYLIST] Complete Python Development Course for Beginners: http://digital.academy.free.fr/playli...
🧑🎓 [COURSE] http://digital.academy.free.fr/courses
📘 [BOOK] Python for Absolute Beginners: https://amzn.to/3NvyOWV
🛒 Shopping and Discounts: http://digital.academy.free.fr/store
💌 Weekly Newsletter for Developers: https://www.getrevue.co/profile/digit...
#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/
✧ / digitalacademyy
✧ / digitalacademyfr
✧ / digital_academy_fr
✧ / digitalacademyonline
♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/store
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧ / digital_academy
✧ https://www.buymeacoffee.com/digital_...
***
In questa pagina del sito puoi guardare il video online Infinite WHILE Loops in Python - Python Tutorial for Beginners della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Digital Academy 09 marzo 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 998 volte e gli è piaciuto 13 spettatori. Buona visione!