O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The while Statement

The while statement repetitively executes a suite until a condition is met. Its basic form is

while( expression ):
      suite

which you can think of in English as “While the expression remains true, execute the suite repeatedly.” Python carries out this instruction by returning to the top of the statement to check if the expression is still true; if so, it executes the suite a second time and once again returns to the top (this is referred to as looping), repeating this process until the expression becomes false. Once that happens, Python stops executing, and the while statement's execution comes to a halt.

One use of the while statement is to remove items from a list—for example, every occurrence of the string cat from the list ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required