[Python] While Loop !
While loop is basically a structure of python, which allows us to loop through and execute a block of codes multiple times.
Let's make while loop
i = 1
while i <= 10: # while + condition:
print(i)
i += 1 # i = i + 1
print("done with loop")
while i <= 10: it means while 1,2,3,4,5,6,7,8,9,10, executing the codes
i += 1 it means i = i +1 , short version. In python, "=" means "include"
Let's run
1
2
3
4
5
6
7
8
9
10
done with loop
so basically,
i = 1
while i <= 10:
print(i)
i += 1
print("done with loop")
it started with i ( it is 1 ) -> 1 is less than 10 -> print 1 -> i + 1 -> start with 2 -> 2 is less than 10 -> print 2 > 2+1 -> start with 3 ................................. untill 11. because 11 is greater than 10 and stop looping and print "done with loop"
Quiz)
while i <= 100:
what if while i <= 100 ?
looping until 101: (1~ 100 + done with loop)