In this video, I show you how to use the two most commons types of loops -- the while loop and the for loop in P5. P5 is a Javascript library that is designed for creating animations, simulations and games. It is a great tool for beginning coders.
These lessons are designed to work with high school students. I use them in my classes to teach kids how to code.
In this lesson I show you how to control a while loop with a variable that is incremented inside the loop. I also explain how to avoid infinite loops in your code.
Next, I demonstrate the for loop and show you how to use the counter variable, that is built in to a for loop, to control the drawing of a series of squares on the canvas.
P5 with JavaScript is a great language for beginning programmers. Check out my other videos on using P5 to learn programming.
If you are a teacher, please feel free to use my videos as part of your curriculum. I have many more videos on my channel. Check them out.
If this has proved helpful, please consider subscribing to my channel. Have a great day!!
![](https://i.ytimg.com/vi/5ZfaC_pYUQc/maxresdefault.jpg)