Why is while True here? | Sololearn: Learn to code for FREE!

+1

Why is while True here?

https://www.sololearn.com/learn/Python/2436/

5/26/2020 12:27:21 PM

3.14

26 Answers

New Answer

+12

It is there to loop through its contents *forever*. It is called an infinite loop, as its condition will be always True. In order to exit from it, you have to use break or exit().

+5

Well, if you want your program to stop working immediately - yes, you can. Break just exits the local block of code, like loop for example. While exit() terminates the program and exits to the system.

+4

Kuba Siekierzyński exit() , will you tell me more about it, plz 🙏🙏

+4

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 It basically terminates the script.

+4

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 You might want to bookmark the thread below and check out the link which is marked as best there, by David Ashton. https://books.goalkicker.com/PythonBook/ https://www.sololearn.com/discuss/444755/?ref=app

+4

Kuba Siekierzyński Thanks for your help 🙂

+3

Kuba Siekierzyński Thanks for the info Can I use it in place of break in my generel programmes ?

+3

Kuba Siekierzyński Code Crasher is ryt I have copied all the text & saved it in my python notes

+3

while True: is there so that it will repeat again and again from start to end until break breaks the loop;)

+3

while True means loop forever. The while statement takes an expression and executes the loop body while the expression evaluates to (boolean) "true". True always evaluates to boolean "true" and thus executes the loop body indefinitely. It's an idiom that you'll just get used to eventually

+2

Kuba Siekierzyński Is there any book which includes such basic topics Bcoz I have not found these topics in any book

+2

Because there is no any base condition to terminate the while loop .So, it will execute the block of statements upto infinite times but you can terminate it with a break statement at the end of your program.If this might helped you give me 5 upvotes bro !

+2

We use a ^while True^ to loop through what it contains forever. We call it an infinite loop(But you can exit from it using break or exit()).I hope you understand it. If you liked this answer please upvote it .

+2

Nidhi Verma Indefinitely or infinitely 🤔🤔🤔🤔

+2

Its there for continuous execution the part of code. In the mention code the user can do continuous calculation by taking input from user until the input is equal to quit ( there will be break which will break infinity loop).

+1

Code Crasher A coding way to do that, would be to create your own web code with links to your favourite threads bookmarked ;)

+1

+1

While loops go through a statement until it's false. If if u just put true the thing would on forever

+1

For infinity time excess of calculate

+1

So that the loop can execute at least one time.