© Engin Arslan 2018
Engin ArslanLearn JavaScript with p5.jshttps://doi.org/10.1007/978-1-4842-3426-6_7

7. Loops

Engin Arslan1 
Toronto, Ontario, Canada

One of things that computers are great at is repetition. Imagine having to create a thousand shapes onscreen with varying parameters. It would take us an unreasonable amount of time to do so with our current programming knowledge. For this kind of case where we want to repeat our code as it is or with variations, we can leverage a programming structure called loops. A loop allows us to execute a block of code over and over again.

We are already familiar with the idea of a loop in p5.js. If you think about it, the draw function is a continuous loop that gets executed over and over again until we ...

Get Learn JavaScript with p5.js: Coding for Visual Learners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.