0

What is 'while loops' and what is it used for?

In Control Structures, chapter no. 7 is While Loops. What is the use of 'i = i + 1' in the following code? i = 1 while i <=5: print(i) i = i + 1 print("Finished!")

21st May 2018, 3:09 PM
Shlok Jaiswal
Shlok Jaiswal - avatar
1 Answer
+ 3
Without i = i + 1 the loop would never stop because i would always be 1 which is called an infinite loop
21st May 2018, 3:24 PM
TurtleShell
TurtleShell - avatar