1、while循环
n=0 #初始条件
while n<=5: #判断
print('hello python') #要重复执行的代码
print(n) #注意同级代码缩进相同
n+=1 #计数器
结果:
hello python
0
hello python
1
hello python
2
hello python
3
hello python
4
hello python
5
#求阶乘和
sum=0
n=1
while n<=3:
i=1
ret=1
while i<=n:
ret*=i
i+=1
sum+=ret
n+=1
print(sum)
结果:9
死循环:条件始终为真。
2、for循环
for i in range(3): #生成0~2一个序列
print('hello')
结果:
hello
hello
hello
#求阶乘和
sum=0
ret=1
for n in range(4):
ret=1
for i in range(n+1):
if i>0:
ret=ret*i
sum=sum+ret
print(sum)
结果:10
![[目标检测] YOLO系列算法讲解](https://i-blog.csdnimg.cn/direct/9dc2a20324864e399896412aa7f2ee07.png)


















