---
title: "Python for while break continue"
author: "fairy_xzc"
date: "2016-09-28T13:50:01Z"
tags: []
categories: ["编程语言"]
slug: "python-for-while-break-continue"
draft: false
lastmod: "2016-09-28T13:53:29Z"
id: 2327550
url: "https://agilestyle.iteye.com/blog/2327550"
---

**原创转载请注明出处：[http://agilestyle.iteye.com/blog/2327550](/blog/2327550)**

 

loop.py

```
databases = ['oracle', 'mysql', 'cassandra', 'mongodb', 'hbase']
for database in databases:
    print(database)

total = 0
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    total = total + i
print(total)

# range(0, 5)
print(range(5))
# [0, 1, 2, 3, 4]
print(list(range(5)))

total = 0
for i in range(101):
    total = total + i
print(total)

total = 0
n = 100
while n > 0:
    total = total + n
    n = n - 2
print(total)

# break
n = 1
while n <= 10:
    if n > 3:
        break
    print(n)
    n = n + 1
print('END')

# continue
n = 0
while n < 10:
    n = n + 1
    if n % 2 == 0:
        continue
    print(n)
```

 

Console Output

![](http://dl2.iteye.com/upload/attachment/0120/2869/ceac6813-94e2-3f1c-8f72-39682a757ad4.png)