Guys any one please say what is for loop and its uses | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Guys any one please say what is for loop and its uses

For loop and its uses

27th Oct 2019, 3:05 AM
THE INDUSTRY
THE INDUSTRY - avatar
1 Answer
+ 1
for loops and while loops are very similar. you should take a look at your lessons, they’re very clear on how to use them. they’re mostly used for iterating through lists/arrays but can be used for other things as well. while i<5: print(“hello!”) for i in range(5) print(“hello!) >> these are both printing “hello!” 5 times. mylist= [“hello”, “welcome”, “goodbye”] x = 0 while x<len(mylist)-1: print(x + “!”) x += 1 for items in mylist: print(items + “!”) >> these are both printing each element from the list with an exclamation point added to the end. see how for loops and while loops can do the same thing, but for loops are just better than while loops in some cases?
27th Oct 2019, 3:52 AM
꧁༺ Jenspi ༻꧂
꧁༺ Jenspi ༻꧂ - avatar