DEV Community

Biagio J Mendolia
Biagio J Mendolia

Posted on

Iteration and Loops in Computer Programming - The Basics

Iteration is a common practice amongst programmers, this is something that is utilized quite frequently and worth having a deep understanding about it! No matter what language you are programming in or what you are building, iteration will probably be needed!

Iteration is a process where a set of instructions are repeated in a sequence, a certain number of times or until a condition is met. When the first set of instructions is executed more than once, it is called an iteration. When a sequence of instructions is executed in a repeated manner, it is then called a loop. Iteration and loops can be extremely powerful when used in the right context!

For example, let's say you have a database of 500 customers and you need to get the information on each customer so that you may mail each one a holiday card. This would be a great scenario to utilize iteration and a loop to print out each customer. Personally, I would use the common “for loop” similar to this:

for (int i=0;i<500;i++)
{
\\Print customerName and customerAddress
}
Enter fullscreen mode Exit fullscreen mode

The way this for loop works is that i is an iterator starting from the customer record, every time the loop is run, it prints the customer information. After printing the information, 1 is added to i and the process is repeated until i = 500!

I hope you enjoyed this quick blog post, thanks for stopping by!!

Top comments (0)