python while statement learning summary

The format of while is:
while condition:
    code block

For example: find the sum of all integers 1-100

x = 0 #summation
i = 1 #count
while i < 101:
	i = i + 1
	x = x + i
print('sum = ',x)
Each time the code block is executed once, the condition will be re-evaluated.


In addition , the while statement has two commands: continue and break
continue is used to skip the while loop
and break is used to exit the while loop . Same as if, while can also be Use else to execute a block of code.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325728153&siteId=291194637