Jan-22-2018, 07:17 AM
(This post was last modified: Jan-22-2018, 07:17 AM by Gribouillis.)
(Jan-22-2018, 07:01 AM)RedSkeleton007 Wrote: I never understood the code statement "while true". While what is true?In python, true is written True with a capital T. The
while True
idiom means loop indefinitely. It may seem strange but it's simple logic: a while condition:
loop runs until the condition becomes false. The True
condition never becomes false, so while True
loops indefinitely, without the need to add a new keyword such as repeat
in the language.C programmers traditionally write
while(1)
to loop indefinitely. This is the ancestor of python's while True
. The latter is cleaner from a purist's point of view because a condition is a boolean rather than an integer. However even python uses 1 for True and 0 for False, for example>>> True + 1 2but
>>> True is 1 False