I just looked at Python's while and for loop today, so I'm going to write it down:
The while statement is a loop condition statement in Python, while judging the condition:
Pass
Break
For example:
i = 1
sum = 1
While I <= 9:
j = 1
While J <= I:
sum = J * I
Print "%d *%d =%d"% (i, J, Sum),
J + = 1
i + = 1
print "\ n"
While statements can be nested IF statements, you can make various judgments of the statements, and then various execution.
For statement:
The FOR statement and for statements in other languages have changed a bit, in which there is no such thing as C: for (i = 0; i<100; 1++) Like this,
The For statement in this case is only for lists or collections or the meta-ancestors (arrays Ah, dictionaries, etc.), the traversal of them, and then each traversal will be traversed by the character of the characters into a custom variable inside, we can output that variable to test.
For example:
Import time
Name = "Liuguibin"
For tamp in name:
Print "%s"% tamp
Time.sleep (1)
Break and Continue:
Break is used in the while and for statement loops to end the loop, as long as our program reads this break, the loop ends.
Example: i = 0
While I <= 50:
Print "This is a test"
i = i * I
Print "%d"% i
i + = 1
Break
Continue is used to end this cycle and then proceed to the next loop, which means that the loop will still be executed, but only if the loop that meets the continue condition is read.
For example:
For ABC in ABCDEFG:
If ABC = ' C '
Continue
Else
Pass
Print "%s"% ABC
Above, that's it!
Python while loop and for loop