While loop syntax structure you can use the while loop while the Expression:while_suite statement while_suite the continuous loop execution until the value of the expression changes to 0 or false when the statement is repeated repeatedly.
# !/usr/bin/env python == 1 while counter <= :+ = Counter + = 1print "result is%d" % sum100
The break statement break statement can end the current loop and then jump to the next statement when writing the program, should try to avoid duplicate code, in which case you can use the While-break structure
#!/usr/bin/env python whileTrue:yn= Raw_input ("continue? (y/n)") ifYninch 'Yy': Break Print " work on"/usr/bin/python2.6/root/pycharmprojects/untitled10/break1.pyContinue? (y/N) nwork onContinue? (y/N) yprocess finished with exit code 0
Continue statement When a continue statement is encountered, the program terminates the current loop and ignores the remaining statements. Then go back to the top of the loop. If the loop condition is still satisfied, the loop body statement continues execution, otherwise exits the loop with all even numbers and
# !/usr/bin/env python =1 while counter <=: + = 1 if counter% 2 = = 1:
continue + = counterprint sum100
Else statement the while statement in Python also supports the ELSE clause else clause that executes a break statement only after the loop completes and skips the Else block
# !/usr/bin/env python == 1 while I <=: + = I + = 1else: Print SUM10
Python while loop