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.14159265358

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

Kuba Siekierzyński I am not sure if you are aware of this, but there are no bookmarks in the iOS app. I would love to bookmark threads! The only thing you can do on iOS is send yourself an email with the share button, and strip the "?ref=app" out of the link because external links do not work in the app either. Posts to personal feeds and posts are not visible from the web, so there is no way to share anything from those threads. I just thought I would share that because it gets very frustrating for iOS users. Especially when people say "just click on x", when "x" doesn't exist. I have seen both apps now, and Android users have no idea how much they take for granted?! 😞

+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

Kuba Siekierzyński I have a duckduckgo page I created for that, but you don't realize that probably 30-40% of the content on Sololearn is only available on Android. External Links do not work on any SoloLearn Page. The app confines the user to internal SL pages. probably a dns jail? There are community challenges and lessons, as well as profile feeds that can not be accessed from iphones or the web... it is only available on Android. iPhone users don't complain because they dont know the content is there. I have Android x86 on a VM at work and downloaded SL. the app is so different I thought the SL clone projects were wish list projects... When I launched the Android version of the app, I saw it was what Android users see. The iPhone app is unbelieveably crippled compared to the Android app. Anyway, I bring this up because it is better to link to external content as above, so iOS users can copy and paste, because they might not be able to get to the SoloLearn page. some links just arent there.

+1

+1

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