Iterating Through Life
30…31…32…CLANK!
Thirty-two free throws in a row. A new personal best!
That may not be impressive to some, but it means a lot to me.
Why?
Despite being 6' 4" and having an intense love for the game, I wasn’t born a gifted basketball player. I was never picked first, and sometimes not at all. I was too slow to be a guard but lacked the strength to punish defenders in the post. I had a broken jump shot and a complete lack of court vision. My chances of making it to the NBA were zero at best.
I could‘ve accepted this fate and walked away from the sport but decided to take a different path. Leaning on my experience as a musician (another skill I was not gifted with), I knew that slow, deliberate practice was the only way to get better. This epiphany led me down a path of creating a system to improve my basketball skills by repeating the same drills over and over until I met a specific goal. I didn't realize it at the time, but this system is called iteration. Since then, I’ve successfully applied this process to sports, instruments, cooking, and most recently coding.
What is Iteration?
Iteration is a fundamental concept that’s used to repeat a specific action multiple times. It’s a powerful tool that can be applied to a wide range of tasks such as free throws, guitar solos, seasoning a dish, or performing calculations. One of the best methods for utilizing iteration is called looping. A loop is a technique for repeating a certain task until a specific condition is met. There are many different types of loops to choose from. Three of the most common are:
- For loops: repeat a certain number of times.
- While loops: repeat while a certain condition is true.
- Do-while loops: repeats at least once, regardless of the condition.
These loops can be used in a variety of scenarios, allowing you to get creative with how to apply them. A perfect example is tracking the results of a practice routine.
Using Iteration to Improve Your Game
I knew that practicing free throws would be a great way to improve my shooting skills. Good shooting form is important for basketball because it helps to increase your shot's accuracy and consistency. This includes the position of your feet, keeping your elbow under the ball, and using a fluid motion with a follow-through.
Starting your free throw routine is similar to initializing an empty set of Arrays:
The next step is to track progress by logging the shots you take. This can be done by creating a for loop that will add your scores to an array:
Now it’s time to create a system for organizing the data you collect:
Finally, commit your scores to memory by adding them all together:
You can iterate through this process again and again until you reach your goals and hit those big milestones!
This approach will help you improve over time regardless of where you started. You can try it for yourself by using my free throw tracker app called “Sure Shot!”:
With most things in life, it’s important to use moderation. Setting healthy goals and avoiding infinite loops are some of the problems to avoid when using loops to record your progress.
Best Practices for Looping
One of the most common mistakes when using iteration is creating an infinite loop. This happens when the loop condition never becomes false and the code inside the loop continues to execute indefinitely. This is bad for a variety of reasons:
- Programs can crash or consume large amounts of resources.
- Entire systems can freeze making them unresponsive.
- Increased power consumption resulting in shorter battery life.
- Loss of time while debugging the problem.
Another common issue is the “off-by-one error,” which occurs when a loop variable is not properly initialized or incremented, causing the loop to execute more or fewer times than intended.
Nested loops, when one loop is placed inside another, can also lead to unexpected behavior if not done correctly.
It’s also important to use the right type of loop for the task at hand. For example, using a “for loop” when a “while loop” would be more appropriate can lead to complex code that’s hard to read.
Coast to Coast
Remember, iteration can be applied in a variety of areas, including basketball, playing an instrument, and learning how to cook. By breaking down your practice into smaller pieces and repeating them using iteration techniques, you can focus on specific skills and refine them over time.
Whether it’s using a for loop to repeat a difficult basketball drill, a while loop to practice a certain musical passage, or experimenting with different variations of a recipe, iteration techniques give you the power to tailor your practice to your own needs and goals. Take some time to think about how you can use iteration to make a positive impact in your everyday life.
CodePen: https://codepen.io/JawaraGordon/pen/dyjzGoL
Resources:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration
https://www.codecademy.com/article/f1-u3-github-pages
Sources: