0
Can someone please explain the while loop for me? I don't seem to get it.
While loop
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. ;)
+ 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)
0
Waw I really appreciate you all.
Thanks for the explanation.
0
While loops will repeat the thing as many times if the condition is true