From the course: Coding for Visual Learners: Learning JavaScript from Scratch

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Nested loops

Nested loops

- [Instructor] So, what if we wanted to fill the height of the screen with circles as well? To be able to do this, we need to write another for loop, that would place circles for the entire length of the cameras for each circle, that is placed for the widths. This requires us to place a second loop inside the first one, effectively nesting your loop inside another loop. So, let's try to do that, because it's easier to show this being done, than to talk about it. So, to be able to do that, I'm going to create another for loop, that's going to make use of a variable called J this time. And J is going to be smaller than, heights divided by diameters. And each time this loop operates, I'm going to add one to J, and I will be placing the ellipse function inside here. And now, instead of actually using zero here, the hard code of zero for the position y, I will be making use of a similar value, that I have used for X,…

Contents