# for 循环
while循环是可控,但是控制不好是不是就是一个死循环。
```python
wenyi_info_list = ['AA','BB','CC','DD','EE']
print(wenyi_info_list[0])
print(wenyi_info_list[1])
print(wenyi_info_list[2])
```
```
AA
BB
CC
```
```python
wengyi_info_list = ['AA','BB','CC']
len(wengyi_info_list)
```
```
3
```
```python
wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
count = 0
while count < len(wenyi_info_list):
print(wenyi_info_list[count])
count += 1
```
```
wenyi
150
260
['piao', '666', 'fish']
zhangdechou
1
2
3
4
5
6
67
```
```python
wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
for i in wenyi_info_list:
print(i)
```
```
wenyi
150
260
['piao', '666', 'fish']
zhangdechou
1
2
3
4
5
6
67
```
# for+break
```python
wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
for i in wenyi_info_list:
if i == 'zhangdechou':
break
print(i)
```
```
wenyi
150
260
['piao', '666', 'fish']
```
# for+continue
```python
wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
for i in wenyi_info_list:
if i =='zhangdechou':
continue
print(i)
```
```
wenyi
150
260
['piao', '666', 'fish']
1
2
3
4
5
6
67
```
# for else 如果for循环没有被break掉,则会运行else下面的代码
```python
wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
for i in wenyi_info_list:
if i == 260:
break
print(i)
else:
print('我没有被break')
```
```
wenyi
150
```
```python
wenyi_info_list = ['wenyi', 150,['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
for i in wenyi_info_list:
if i == 260:
break
print(i)
else:
print('我没有被break')
```
```
wenyi
150
['piao', '666', 'fish']
zhangdechou
1
2
3
4
5
6
67
我没有被break
```
# while和for循环异同
异:while循环需要条件,for循环不需要条件
同:都是循环
# for循环实现loading......
```python
for i in range(0,6):
print('.')
```
```
.
.
.
.
.
.
```
```python
for i in range(0,6):
print('.',end = '')
```
```
......
```
```python
import time
s = 'loading'
print(s,end = '')
for i in range(0,6):
print('#',end='')
time.sleep(1)#字符出现时间间隔1秒
```
```
loading######
```
```python
import time
for i in range(0,6):
if i == 0:
print('[#',end = '')
if i == 4:
print('#]',end = '')
print('#',end = '')
time.sleep(0.5)
```
```
[######]##
```
```python
```