> For the complete documentation index, see [llms.txt](https://george-jen.gitbook.io/data-science-and-apache-spark/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://george-jen.gitbook.io/data-science-and-apache-spark/while-loop.md).

# while loop

while loop iterates when condition is True until condition is False or when immediate break statement inside the loop body is run.

```
a=0
while a<5:
    print(a)
    a+=1
```

or calculate Fibonacci series

```
a, b = 0, 1
fib=[]
while True:
#    print(a)
    if len(fib)>=10:
        break
    else:
        fib.append(a)
    a, b = b, a+b 
    print(fib[-1], end=" ")
```
