[Tutor] While truth
C Smith
illusiontechniques at gmail.com
Tue May 20 20:50:35 CEST 2014
Of course that isn't very useful code. I thought it might be a useful
quick test for someone learning how while loops treat different
values.
On Tue, May 20, 2014 at 2:46 PM, Danny Yoo <dyoo at hashcollision.org> wrote:
> 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