Ever felt tired or even bored while doing a task again and again ?Well it is a similar feeling for the compiler 💻 when you are a executing the same block of code repeatedly.
"I feel exhausted, my memory running low...it's not a good feeling" - compiler
So, to ease it for the compiler as well as the programmer, the developers (big brain people 🧠) of programming languages have created a holy solution, iteration 🔁.
What is iteration ?
Iteration is to repeat a block of code until it produces a desired outcome.
E.g. You want to transfer 5 notebooks from one table to another, but you can only take 1 notebook at a time. So you are going to take 1 notebook to the other desk and then return back. If you repeat this process 5 times you will complete your task. This repeating is iteration.
How is iteration implemented in coding ?
Iteration can be used in coding to decrease the file size as well as increase the efficiency of writing and executing the program. The concept of iteration🔁can be used through loops in your code. These are coding statements that make it possible to iterate a block of code.
Aren't they smart 🧐
Types of Loops in Python
1. While loop
Easiest loop available in python
while condition:
Code to be executed while condition is true
Default code structure⬆️
i = 1
while i <= 5:
print("Value of i is",i)
i+= 1
This code will print numbers from 1 to 5⬆️
This is it for now! Will see you again in sometime...