why do we use while True: | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

why do we use while True:

13th Jul 2016, 4:12 PM
JeyaMurugan
3 Antworten
+ 2
while True: is like while (1) of C. it is capital T in True
13th Jul 2016, 5:52 PM
Sathyanarayana Hadadi
Sathyanarayana Hadadi - avatar
+ 1
Its for infinite loop. For example if you want to run a block of code forever you may want to use this technique For example while True: name=str(input("enter your name:" )) print("hello "+name) if name == 'quit': break now the above code would run the while loop forever since its always True (while loops breaks when condition is false) . Inorder to break it we can use 'break' keyword with a 'if' condition. if the input you give is equal to 'quit' the loop breaks
13th Jul 2016, 4:23 PM
sundar
sundar - avatar
+ 1
these kinds of while loops are used for infinite times iterating,break statement will require inside the loop (within a if block)to break the loop.
15th Jul 2016, 3:13 PM
Charith