Programming in Python (Part-6)


Loops are an important concept in programming languages. A loop is like a sequence that repeats its task until a specified condition becomes true. Think of it like a process which is continuously running and then some condition is defined such as when counter reaches prescribed number terminate the process.

So, before we begin just wanted to share that you can also check and learn this part through video tutorial as well

In python there are two types of loop:

-> While loops
-> For loops

While Loop:
Using while loop we can execute a set of statements as long as the defined condition is met.

# Example - 1

i = 1
while i < 6:
  i += 1

# Example - 2

computer_brands = ["Apple", "Asus", "Dell", "Samsung"]
i = 0
while i < len(computer_brands):
	print computer_brands(i)
	i = i + 1     

For Loop:
For loop are used when we want to iterate over a sequence, a sequence can be list, tuple, dictionary, set, string or range.

# Example - 1

Number_list = [1,2, 3, 4, 5,6, 7]
for num in Number_list:
# Example - 2
# Prints out the numbers till 0 to 10
for x in range(10):

You can find code with examples as well on my github page…

Thank you for reading…

Leave a Reply

Your email address will not be published. Required fields are marked *