Loops & Functions

Loops

Remember, a for loop repeats an action for multiple iterations, based on the conditions that you give it.


A more sophisticated understanding of loops can be found in the book Eloquent Javascript.

The Coding Train example on multiple kinds of Javascript with Dan Schiffman

Here is an additional text tutorial on for loops.

Here is an additional information video on loops once you have a little experience in creating and utilizing for loops.


Functions

A function is a block of code that can be called when needed and otherwise ignored. Think of a function like a power drill. It serves a very specific purpose, but you don’t want to have it running all of the time; that would be dangerous and annoying. You can change out the bits of the drill whenever you need to use it in order to achieve a slightly different purpose, however the way that the drill still functions is always the same. (the drill bits are analogous to the arguments in our functions). Once we have used our drill we can put it away until the next time we need it. The final product of our drilling can be used for something else (like a return value), or it can be its own completed entity.

drill

Here are a few videos discussing the use of functions in P5.js