Let’s talk about the basics of iteration. In this episode, you will learn about iteration as it is a key process in programming.
Your key takeaways are:
- Iteration is repeating a sequence
- It’s a loop
- Separate the iteration functionality from the container
Here’s the primary question: How do you iterate through a container? How do you “say or do a thing again or again and again” (Merriam-Webster.)
What is Iteration?
- the action or a process of iterating or repeating:
- as a procedure in which repetition of a sequence of operations yields results successively closer to a desired result
- the repetition of a sequence of computer instructions a specified number of times or until a condition is met — compare recursion
- one execution of a sequence of operations or instructions in an iteration
It’s a loop!
Iterating Through an Array
- Set the pointer position to 0.
- Fetch the key and data (value.)
- Do the work.
- When done, number of elements > pointer position?
- If yes, then increment pointer position.
- If no, stop.
- Go to step 2 (repeat.)
What’s needed to iterate a container?
- Pointer in the collection
- Functionality to do the iteration sequencing
- Where should this functionality be?
- Should it be separate or a part of the collection?
Coupling: “the act of combining two things.”
- the act of unlinking two things
- separating two things from one another
- you can swap out implementation
- less complexity
- promotes reuse
- a change in one module does not cause a ripple effect
Congratulations, you just learned a key software and quality principle!
Whoever says that coding is hard, just smack them.
Total Lab Runtime: 02:17:55
- 1 Lab Introductionfree 06:21
- 2 User-Friendly Expression of Informationfree 22:42
- 3 Fundamentals of Syntaxfree 08:57
- 4 Decision Branching - if/then/elsefree 10:39
- 5 Decision Branching – switch/casefree 07:47
- 6 Basics of Iterationfree 14:14
- 7 Iteration in Practicefree 12:51
- 8 Order of Executionfree 10:55
- 9 Abstractionfree 11:45
- 10 Scoping – Who Can Communicate With Whomfree 31:44