0

in very simple words what is the difference between for and while loop?

for and while loops

26th Jun 2020, 9:54 AM
Abhinraj
3 Answers
+ 4
In simple words, while loops keeps terminating the code inside it until it evaluates to false and for loop is used for performing operations on each item of the list or iterating it a given number of items. Example 1: while True: print("Hello world") #this will print it repeatedly because the condition will remain always true. Example 2: for i in range(10): print ("Hello world") #it will print Hello world ten times.
26th Jun 2020, 11:09 AM
Arctic Fox
Arctic Fox - avatar
+ 2
for loop is for when you know how many times you want to loop. while loop is for when you dont.
26th Jun 2020, 9:57 AM
Slick
Slick - avatar
+ 1
kk.thank you to both
26th Jun 2020, 11:19 AM
Abhinraj