Opening Hours :7AM to 9PM
Looping Statements are used to execute a statement several number of times based on the condition.In Python language these are classified into following types.
1.For Loop
2.While Loop
for variable in range('starting value','ending value','increment/decrement'): ... ... ...In the above syntax :
def myfun(): for x in range(1,10+1,1): print(x) if __name__=="__main__": myfun()
def myfun(): for x in range(10,0,-1): print(x) if __name__=="__main__": myfun()
Nested For Loop :
One for loop within another for loop is knows as Nested For Loop
Syntax
for variable in range('starting value','ending value','increment/decrement'): for variable in range('starting value','ending value','increment/decrement'): ... ... ... ... ... ...In the above syntax :
def myfun(): for x in range(1,7,1): for y in range(1,4,1): print("*",end="") print(end="\n") if __name__=="__main__": myfun()
def myfun(): for x in range(1,7,1): for y in range(1,x+1,1): print("*",end="") print(end="\n") if __name__=="__main__": myfun()
Row Decrement column increment ****** ***** **** *** ** * def myfun(): for x in range(6,0,-1): for y in range(1,x+1,1): print("*",end="") print(end="\n") if __name__=="__main__": myfun() ........................... Column Decrement row increment ****** ***** **** *** ** * def myfun(): for x in range(1,7,1): for y in range(6,x-1,-1): print("*",end="") print(end="\n") if __name__=="__main__": myfun()