Topics About Contact Resources Quotes

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.
  • 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