While Loops

While Loops

In [1]: i=1

In [2]: while (i<5):
   ...:     print(i)
   ...:     i=i+1
   ...:     
1
2
3
4

In [3]: i=0

In [4]: instructors=["Duan","Charlie","Stuart","Allen"]

In [5]: while (i<4):
   ....:     print("Hello,", instructors[i])
   ....:     i=i+1
   ....:     
Hello, Duan
Hello, Charlie
Hello, Stuart
Hello, Allen

Last updated

Massachusetts Institute of Technology