Loops in Python.
Looping
Looping is a continuous execution of a statement till the condition becomes false or till it set the end point. In python two types of looping supported , they are:
While loop
While loop is a conditional control statement. It will be executed based on the condition, if the condition is true it will execute the body of the loop till the condition become false
Example:
Write a python program to add 10 consecutive number starting from 1 using while loop.
For loop
The for loop in python a slightly different from other programming language. The python for loop iterate through each value in a sequence,where squence of object hold multiple items of data store one after another.
For loop in python which repeats a group of statement for specify number of times. The keyword 'for' and 'in' are essential key word to iterate the sequence of value.
Example:
Use for loop to print the numbers from 1 to 5.
Range Function
This sis inbuilt function in python called Range function, which is used to generate list if integers. The range function has three parameters.
range(1,6,2)
Nested Loop
The for and while loop statement can be nested in the same manner in which if statement are nested. Loop within the loop or when one loop is inserted within another loop then it is called Nested Loop.
Comments
Post a Comment