[Tutor] While truth

Danny Yoo dyoo at hashcollision.org
Tue May 20 20:46:55 CEST 2014


On Tue, May 20, 2014 at 11:44 AM, C Smith <illusiontechniques at gmail.com> wrote:
> You can test out a condition like this in IDLE like so:
> while 6:
>     print "yes its true"
>     break
>
>
> while 0:
>     print "yes its true"
>     break
>
>
> while -1:
>     print "yes its true"
>     break
>
>
> emptyList = []
> while emtpyList:
>     print "yes its true"
>     break
>
> This way you don't have to deal with an infinite loop.
> It will print "yes its true" once, if it IS true and then "break" will
> break you out of the loop.


That being said, if we're going to go through these contortions, we
might as well use "if", right?  :P


The infinite loops in the examples above are a complete distraction
from the main point, I think.


More information about the Tutor mailing list