new to While statements

Dan Sommers dan at tombstonezero.net
Wed Aug 7 01:52:11 EDT 2013


On Tue, 06 Aug 2013 22:42:42 -0700, snakeinmyboot wrote:

> I wish I understood half of what you posted Dan. Time to hit the books

So think about the "while" statement:  it takes an expression (the part
before the colon) and a suite (the part after the colon and before the
next statement at the same indent level as the while statement),
evaluates the truthiness of that expression, and executes its suite if
the expression is true.

So "while True" evaluates True, discovers that it's true, and executes
its suite.

So "while 'some string'" evaluates 'some string,' discovers that it's
true, and executes its suite.

The language sees both literals the same way, but one of them is much
more useful to a human reader.

Statements like "while True," "while x < 0," and "while object.method()
!= False" are more conventional, but really no different from "while y"
and "while 'a description of what this loop does.'"



More information about the Python-list mailing list