Table of Contents
Loop in Python
- Loop is a command which means repeat again an again using logics.
- In python loops are two types:
- while loop
- for loop
While loop in python
- It is an entry-controlled looping statement.
- It is used to repeat a block of statements until the condition becomes True.
while (condition): statement increments/decrements
Example of while loop
#program to print 0 to 10 number using while loop i=0 while i<=10: print(i) i=i+1
For loop in python
- For is one type of python keyword.
- A for loop is used for iterating the statements.
- For loop is used in a list, a tuple, a set, a string, and a dictionary.
Use of for loop
y=[1,2,3,4,5,6,7] #This is a list for x in y: print(x)