Loops in Python : Simple Example

Hi Guys,

Here is the simple example that I made to explain  fundamental ways to use for and while loop. Python makes usage of loops extremely easy because it has no bracket system as such. Just take care of indentation and you are good to go. Bonus is indentation makes your program look nicer. Here we go :



 # Program to show loops in python
for i in range(0,4):  # Takes min=0, max=3 
    print("For loop output : %d"%(i))
# Please note that i has a value 3 at this point; after for loop
while i < 7:
    print("While loop output : %d"%(i))
    i+=1


Output : 


No comments:

Post a Comment