Interactive For Loop
The for loop is a key building block of programming.
When we need to do something multiple times, a simple for loop is often the best tool to use.
A for loop has 4 components.
When we need to do something multiple times, a simple for loop is often the best tool to use.
A for loop has 4 components.
- start value (usually set to 0)
- max value (when stop looping when we reach this value)
- iteration value (how much to change each loop)
- body (what code to run each loop)
For Loops Are Simple
We call it a for loop because it loops for number of iterations.
We change a variable until the condition to stop looping is met.
Our variable is commonly named I or j but could be named anything we want.
We tell our variable where to begin and where to end (the end could be less than the beginning) and how much to change each loop iteration.
The body could be anything, this is where our custom code comes into play.
Conclusion
We can do incredible things with a simple for loop.
It is one of the simplest yet most powerful tools of programming.
Resources
- Elements of Programming
- Beginning Math and Physics for Game Programmers
- Euclid's Elements (The Thirteen Books)
- From Mathematics to Generic Programming
- Data-oriented design: software engineering for limited resources and short schedules
- Design of Design, The: Essays from a Computer Scientist
- Mythical Man-Month, The: Essays on Software Engineering, Anniversary Edition
- More Effective C++: 35 New Ways to Improve Your Programs and Designs
- Mathematics for Machine Learning
- The Pragmatic Programmer: Your Journey To Mastery, 20th Anniversary Edition (2nd Edition)
- Schaum's Outline of Essential Computer Mathematics 1st Edition
- All recommended resources