Python loops

Estimated reading: 2 minutes 656 views

Python For loop with one parameter

in this example u , will see the giving one value in the range.

				
					for i in range(10):
    print(i)
				
			

Python For loop with two parameter

in this example u , will see the giving two parameter in the range. where the first parameter will be treated as starting limit and second parameter is treated as ending limit

				
					for i in range(10,20):
  print(i)
				
			

Python For loop with Three parameter

in this example u , will see the giving Three parameter in the range. where the first parameter will be treated as starting limit and second parameter is treated as ending limit and last parameter is treated as interval.

				
					for i in range(10,20,2):
  print(i)
				
			

Python For loop with decending order

in the below example u will see the example for loop with decending order in python.

				
					for i in range(40,20,-2):
  print(i)
				
			

Python For loop nested

A nested loop is a loop inside a loop.

The “inner loop” will be executed one time for each iteration of the “outer loop”:

				
					for i in range(1,5):
  for j in range(7,10):
    print("i value is ", i)
    print("j value is ", j)
  print("\n")
  print("\n")
    
				
			

While loop

With the while loop we can execute a set of statements as long as a condition is true.

				
					i = 1
while i < 6:
  print(i)
  i += 1
				
			

Leave a Comment

CONTENTS