For Loop in Python

#----------------------------- 1- one vertical line in for loop  --------------------

# for loop iterates for n-1 times Eg: for 9, it iterates for 0 to 8

n = int(input("Enter the range : "))

for i in range(n):  #  syntax : for variable in range(start , end, skip):
    
    print(i)
print()
print("After Skiping")
for x in range(2,n,2):  # skips every second value for every iterate
    print(x)
#----------------------------- 2- factorial in for loop  ---------------------------

num = int(input("Enter the  nubmer : "))
fact =1

for i in range(num):
    i+=1
    fact = fact *i
print("Factorial of ",num, "is",fact)
#----------------------------- 3- splitting word in for loop  ---------------------

string = input("Enter the string: ")

print("Seperated ")
for i in string:  # after every iteration i value increments automatically
    print(i)
#----------------------------- 4- nested for loop  ---------------------------------
adj = ["Pyhton", "HTML", "PHP"]
fruits = ["Django", "CSS", "MySql"]

count =0
print("Column 1\t Column2")
for x in adj:
  for y in fruits:
    count+=1
    print("Row ",count,"",x,"\t\t", y)
#----------------------------- 5- continue, pass, break in for loop  -----------------

print("Break")
for b in range(12,345,12): 
  if(b >100 ):
    print(b)
    break  # stops the iteration
  else:     # does not iterates for else once break
    print("Not broken")

print("Continue")
for a in range(2,34,3):
  
  if(a % 2 == 0):  # checks whether the number is even 
    continue       # if even number then skip the values nd go for next 
  else:
    print('/',end='')     # continues to else 
  print(a)

print("Pass")  
for i in (12344):
  pass     # pass is used to avoid error whic occurs when empty loop is defined
#----------------------------- 6- Tables using for loop  ---------------------

n =int(input("Enter the numebr : "))
mul =1
print()
for i in range(1,16):
    
        mul = n*i
        
        print('-----------------------------------------')
        print(n,"\t*\t",i, "\t=\t",mul, "\t|")
        
print('-----------------------------------------')

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available