What is the use of using while True: statement? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

What is the use of using while True: statement?

7th Feb 2017, 7:06 AM
Ashish Ranjan Jha
Ashish  Ranjan Jha - avatar
4 Antworten
+ 4
As 'True' is always True, it becomes an infinite loop.
7th Feb 2017, 7:37 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 4
Suppose your program has to take an unknown number of user inputs and stop when user wants to. In such cases, an infinite loop can be used and a break; statement can be used to stop iterations.
7th Feb 2017, 2:04 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 1
Creating a program that takes your input and gives you an output While True: a=input("Enter a number for me to add\n>>>>") print(a+5) print("\n") that way you can just give it a number whenever and all the program will do is return the sum of your number and 5. Enter a number for me to add >>>>5 10 Enter a number for me to add >>>>7 12 Enter a number for me to add >>>>3 8 Enter a number for me to add >>>> ect
7th Feb 2017, 7:29 PM
Hello World!!!!
Hello World!!!! - avatar
0
but what's the advantage of making the loop run forever??plz suggest one example....
7th Feb 2017, 12:30 PM
Ashish Ranjan Jha
Ashish  Ranjan Jha - avatar