In this video, I have explained regarding Looping in Python and started with the syntax and detailed explanation of For loop. This video requires prior knowledge of my previous video where i have created a variable, stored it, created a list, indexing of values and operators. I have explained this part using a practical example where Loops can be used. Loops are used to execute a piece of code multiple times so as to perform a particular task. The detailed explanation with an example is covered in this video.

FOR LOOP IN PYTHON

Loops are used to execute a piece of code or set of statements multiple times in a program as long as the condition is true. For loop is the one of the loop structure in Python. It has the ability to iterate over the items of any sequence using “range”, “in” and some other predefined keywords.

Syntax:

For iterating_var in sequence:

            Statement(s)

Here, a sequence is created which have an expression either defined by list, tuple and string. The first item of that sequence is assigned for iteration to iterating_var. After that, the block of statements are executed. The loop will iterate or execute until the complete sequence is over. When the sequence is completed, program comes out of the loop and remaining statements are executed. In Python language, during any of the decision making, control statements and looping indentation is very important because, it specifies the set of statements to be a part of single code or block. Since no brackets are used to specify the complete code with in, indentation is used.

Flowchart:

Watch my video to get the detailed view of how to use while loop with a practical explanation.