0

Can someone please explain the while loop for me? I don't seem to get it.

While loop

29th Jul 2021, 11:49 PM
Timi
Timi - avatar
5 Respuestas
+ 3
'While' loop continues to execute anything you put in it while its statement is True. e.g. while i==1: print("hello") will print "hello" while 'i' has a value of '1' or e.g. while True: print(''hi') will print "hi" forever, cuz True is always True. ;)
30th Jul 2021, 12:18 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
''' You have already received some good answers about HOW to use a while loop, but I would like to try to explain WHEN to use a while loop. A for loop is normally used when you have a preset number of operations to preform. Example:''' for i in range(4): print(input()) ''' A while loop is used when you need to keep operating an unknown number of times until a condition has been met. Example:''' user = input() while user != 'exit': user = input() print(user)
30th Jul 2021, 10:25 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Waw I really appreciate you all. Thanks for the explanation.
30th Jul 2021, 5:38 PM
Timi
Timi - avatar
0
While loops will repeat the thing as many times if the condition is true
31st Jul 2021, 6:12 PM
Vijay. G.V