while loop
while loop iterates when condition is True until condition is False or when immediate break statement inside the loop body is run.
1
a=0
2
while a<5:
3
print(a)
4
a+=1
Copied!
or calculate Fibonacci series
1
a, b = 0, 1
2
fib=[]
3
while True:
4
# print(a)
5
if len(fib)>=10:
6
break
7
else:
8
fib.append(a)
9
a, b = b, a+b
10
print(fib[-1], end=" ")
Copied!
Last modified 1yr ago
Copy link