DELAPARRA
Index
Color
NL
Category: Programming paradigms

Iteration

Explained by Updated

What is Iteration?

Iteration: Repeating a block while a condition holds — for, while, do-while loops. Iteration means repeating a block of code, usually with a for, foreach or while loop, until a condition is met or every item has been processed. It is one of the basic building blocks of programming. Processing a list of orders, retrying a request a few times or reading a file line by line all use iteration.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Iteration

What should you keep in mind with Iteration?

Two practical points help. Make sure every loop ends: a while loop whose condition never becomes false will hang a request or worker. And watch what happens inside loops. A database query inside a loop over 500 orders means 500 queries, the well-known N+1 problem. Loading related data in advance, with eager loading in Laravel for example, turns that into two queries and often makes a page many times faster.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with I

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.