0

While true: statememts

why using true word using while loop doesnt give error? there should be a condition against true word..

8th Jul 2017, 4:13 PM
Anshuman Sharma
Anshuman Sharma - avatar
2 Answers
+ 2
Putting a condition after the 'while' keyword will return a boolean result ('True' or 'False')... Putting the keyword 'True' alone after the 'while' is same that putting the condition result... So 'while True:' is equivalent to 'while 42 == 42', but spare some cpu cycles ^^ (and do an infinite loop, in which you have to handle a base case to break the loop :P)
8th Jul 2017, 6:52 PM
visph
visph - avatar
0
true is not a simple word, it's a keyword. boolean operators returns true (1) if the condition is true, and false (0) if the condition is false. you can replace an unnecesary condition with true if you want to make the loop/conditional run always
8th Jul 2017, 4:25 PM
Andrés04_ve
Andrés04_ve - avatar