Hey there! Today we will explore how computers search for things and why using loops makes our code so powerful.
When we want a computer to search through a list, we use a search algorithm. To do this, we write code that repeats the same check on each item until we find a match.

Instead of writing a separate line of code to check every single item, we use iteration, which is also called a loop. A loop repeats a block of code automatically, saving us time and making our code much shorter.
Let us analyze the benefits of iteration. If we have a list of one thousand items, a loop only needs a few lines of code to check them all, whereas writing manual checks would take thousands of lines.
Analyze how using a loop (iteration) makes our code better when searching for the number 7 in this list: [2, 5, 7, 9]. We will compare manual coding to loop coding.
- First, we look at the manual way. We would have to write: 'Is the first item 7? No. Is the second item 7? No. Is the third item 7? Yes!' That is three separate comparison steps we had to write by hand.
- Next, we look at the iterative way. We write one single loop: 'For each item in the list, check if it equals 7.'
- Then, we analyze the code size. The loop only takes about three lines of code, no matter how long our list grows.
- Finally, we evaluate the benefit. If our list grew to one million items, our loop code would stay at three lines, while the manual code would grow to one million lines! Iteration makes our code clean, smart, and easy to change.
