While Loop statement
The while statement is used to loop the execution of a program that, under certain conditions, loops through a program to handle the same tasks that require repeated processing. Its basic form is:
while Judging Condition: Execute statement ...
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.
The loop ends when the condition false false is judged.
While statement there are two other important command Continue,break to skip the loop, continue used to skip the cycle, break is used to exit the loop, in addition, "judging condition" can also be a constant value, indicating that the loop must be set up, the following:
#-*-coding:utf-8-*-I= 1 whileI < 10: I+ = 1ifi%2 > 0:#Skip output when non-even Continue PrintI#output even 2, 4, 6, 8, tenI= 1 while1:#the cycle condition of 1 must be set PrintI#Output 1~10i + = 1ifI > 10:#when I is greater than 10 o'clock jump out of the loop Break
For Loop statement
A For loop can traverse any sequence of items, such as a list or a string.
for inch sequence: statements (s)
#for in'Python': print i
The output results are as follows:
Python
Looping with Else statements
In Python, for ... else means that the statement in for is no different from normal, while the statement in else is executed when the loop is executed normally (that is, for not breaking out by break), while ... else is the same.
Pass Statement
Pass does not do anything, generally used as a placeholder statement.
#for in'Python': if' H': pass print'Pass ' print i
The output results are as follows:
Pyt Pass Hon
Python Looping statement notes