0
What is the use of using while True: statement?
4 ответов
+ 4
As 'True' is always True, it becomes an infinite loop.
+ 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.
+ 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
0
but what's the advantage of making the loop run forever??plz suggest one example....