python while循环



while和for的不同

while循环的最大作用是指定次数的循环
for循环最大的左右就是遍历
while和for之间是可以互换,continue和break也可以在for里面使用

a = 0
while a < 100:
    print("hello world")
    a += 99


循环计数从0开始
a = 0
while a < 6:
    # 0, 打印第一次,
    print(a)
    # 0打印完第一次,
    a += 1   # 0 = 0 + 1
a = a +1


循环从300到415之间所有数据累加和

num = 0
a = 300
while a <= 415:
    num = num + a
    print(num)
    a += 1
    print(a)


0到100循环
num = 0
a = 0
while a <= 100:
    num = num + a
    a += 1
    print(num)

num = 0
while num < 5:
a = 0
while a <= num:
print(a+1, end= "")
a = a + 1

print()
num = num +1
 

 

上一篇:redis学习记录


下一篇:电脑常识[堆漏洞][Fastbin attck][0ctf][pwn]看不懂可以顺着网线来打我,极其详细的babyhea