Python while Loop statement
in Python programming, the while statement is used to loop the execution of a program, which, under some conditions, loops through some segments of the program to handle the same tasks that require repeated processing.
the execution statement can be a single statement or a block of statements.
The judging condition can be any expression, and any value other than 0, or non-null (NULL), is true.
when the condition false false, the loop ends.
650) this.width=650; "src=" http://www.runoob.com/wp-content/uploads/2013/11/python_while_loop.jpg "alt=" Python_ While_loop "/>
Example :
#! /usr/bin/python
Count = 0
while (Count < 9):
print ' The count is: ', count
Count = Count +1
Print "Good bye!"
The above code executes the output result:
the count is: 0the count is: 1the count is: 2the count is: 3the count is: 4the count is: 5the count is: 6the count is: 7the count is: 8good bye!
The while statement has two other important commands, Continue,break, to skip loops.
-
The Continue is used to skip the cycle.
-
Break is used to exit the loop, in addition to the "judging condition" can also be a constant value, indicating that the loop must be established.
Here's how:
# Continue and Break usage:
i = 1
While I < 10:
i + = 1
If 1%2 >0: # Skip output when non-even
Continue
Print I # output even 2, 4, 6, 8, ten
i = 1
while = 1: # The loop condition is 1 must be set
Print I
i + = 1
If i >: # When I is greater than 10 o'clock jump out of the loop
Break
This article is from the "HCWJ" blog, make sure to keep this source http://luwenjuan.blog.51cto.com/10967115/1922505
Python while Loop statement