Hey guys, welcome to chapter 3
In this chapter we will take a glance at loops. Well, a loop in programming is a repetition of a statement or group of statements until
and unless an event occurs. That event is usually based on a condition or the end of an object
For loop basically works on iterables. An iterable is an object from which a part or member can be taken at a time
String, list, etc. Still confused? Let's see a program example. Suppose x equals to a list and that contains 4, 6, 8, 7 and 5
So now we are going to use a for loop. So for i in x, print i
i here will hold each item from the list and print that on screen each time the loop executes
This will continue until the last item of the specified list is displayed
Let's see another example to print out numbers from 1 to 10
We can use a range function along with the for loop. So how that looks like
Well, for i in range, now specify the range 1 to 11 because 11 here, the last digit is
excluded so we have to use 11 here and then print i
The i here will hold each value within the range of 1 to 11 and display that on screen
each time the loop runs. The loop will run until the specified range comes to an end
Do some practice and that would significantly help you understand the concept of for loop
Have any questions? Please ask in comments. That was all for now
Thanks for watching