# not understood While true:

 0 I have not understood correctly not understood While true: does it mean that if it return -1 then it is false other wise true asked 11 Mar '12, 05:16 Owais Ahmed 201●4●7●21 accept rate: 0%

 0 What unit? What video? What Python code? What are you asking? answered 11 Mar '12, 05:19 Alberto Cid 1.0k●3●10●30
 0 def get_all_links(page): links = [] while True: url, endpos = get_next_target(page) if url: links.append(url) page = page[endpos:] else: break return links  link This answer is marked "community wiki". answered 11 Mar '12, 05:21 Owais Ahmed 201●4●7●21 Elise 3.7k●5●16●56
 0 While True: means that you are creating an infinite loop. If you don't create a condition to stop it, it will continue forever. For example:  n = 3 While True: if n < 1: break print n n = n - 1  This loop will break as soon as n will be equal to 0. If the condition to break the loop wasn't there, it would have continued forever. answered 11 Mar '12, 05:25 Elise 3.7k●5●16●56
 0 so for using while true: one must have to give a condition that at which it will break. otherwise it will be infinite and continue forever. so why is this needed when we can do it by giving any other condition ... answered 11 Mar '12, 05:28 Owais Ahmed 201●4●7●21 If you can give it a condition, no need to use it. Sometimes, it makes your code more easy, but it does not have to be used if you feel you don't need it. In the example above, it makes no sense to use it because we can replace True by the very simple condition n > 0. If we had more complicated / several conditions, it would be very useful. (11 Mar '12, 05:33) Elise It is not "needed", you just have it there and you can use it if you want... If you don't want, don't use it. (11 Mar '12, 05:36) Alberto Cid
 0 The while loop is a control flow construct that checks an expression that must result in a boolean value (True or False). If the expression results in True the while loop will allow the code within it's code block to execute (anything one indentation level greater than the line that has the While loop on it). Example: while True: print 'Hello' print 'Goodbye'  The two print statements above will execute FOREVER because the expression that while is using to base its decision on whether to execute the print statements is always true (because it's the boolean value True). To make it so the above print statements don't execute until the end of time there are two options: Use an expression that will eventually evaluate to False. Leave the loop manually. Leaving the loop means getting the program to execute code that isn't in the code block that the loop has control of. This is where the break statement and return statement. I break statement is pretty straight forward....it breaks the program out of the loop. The return statement also changes the execution of code. If you're using a return statement that means you're in a procedure and if your loop is being run that means a different part of the program called that procedure. Executing a return statement returns the program back to the location the procedure was called from (technically just after it) so that is also why a return statement can get your program out of a loop. The while loop itself doesn't return anything...it just blindly checks "can I let the code within my code block run?" to get the answer it checks to see if the conditional expression associated with it results to True or False. Hope this helps some. Guess I spent too much typing :) Looks like others have helped out. answered 11 Mar '12, 05:47 David Smith 1.2k●6●12●36 Having a same thing eplained in many different ways is a good thing! :) (11 Mar '12, 06:17) Elise
 0 The while loops works like this: while condition: While the condition is true, you execute the code in the while loop, otherwise you don't while True: While True is true, you execute the code in the while lopp, otherwise you don't. As True is always true, it is a never ending loop, or an infinite loop. And the only way to get out of it is to break (which basically means "get out of this loop NOW", or if it's in a procedure a return is possible too. If you choose to return the value, it won't have anything to do with the condition. example:  def something(): while True: return False print something() # will print False  answered 11 Mar '12, 06:11 Tom Lether 1.3k●10●22
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×15,299
×43
×16