# Homework help with loops

**URL:** https://discourse.processing.org/t/homework-help-with-loops/41903
**Category:** Coding Questions
**Tags:** homework
**Created:** [May 3, 2023, 5:32pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903 "2023-05-03T17:32:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Computerscience](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Computerscience](https://discourse.processing.org/u/Computerscience)
#### Post date: [May 3, 2023, 5:32pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/1 "2023-05-03T17:32:48Z")

</div>

Question: Draw a character that would fit within a 40×40 pixel box. Once you have this working, use for loops to “tile” the image 100 times on a 400×400 pixel canvas. Hint: can you do this using only 2 for loops?

problem: every time I attempt this program it always fails and I cant make it only with 2 loops, can anyone help me start off the code? It wont let me write my code.

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [May 3, 2023, 5:52pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/2 "2023-05-03T17:52:49Z")

</div>

> [@Computerscience](#):
>
> every time I attempt this program

Hi

Post your attempt

Here is some references

> **[p5.js Web Editor](https://editor.p5js.org/marynotari/sketches/ryAqIX43b)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

[![](https://img.youtube.com/vi/1c1_TMdf8b8/maxresdefault.jpg "4.2: Nested Loops - p5.js Tutorial") ](https://www.youtube.com/watch?v=1c1_TMdf8b8&t=139s)

---

<div class="post-metadata">

### Author: ![Computerscience](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Computerscience](https://discourse.processing.org/u/Computerscience)
#### Post date: [May 3, 2023, 6:17pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/3 "2023-05-03T18:17:40Z")

</div>

Its working now, I can type my code here it is.

```auto
function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  for (var x= 0; x <= width; x += 40) {
    for (var y= 0; y <= height; y += 40) { 
    fill(255,0,255);
    ellipse(x, y, 25, 25)
    }
  }
}

```

I put the for loops together as I cant figure out how to make it so that I only have two loops but have the same out come.

How do I make it so that it tiles it 100 times.

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [May 3, 2023, 6:44pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/4 "2023-05-03T18:44:26Z")

</div>

Hi  
Change this values x += 40  
Y+= 40… let’s say make it 10  
See what happens

Then change this values

ellipse(x, y, 25, 25) and see what happens

Edit

for (var x= 0; x \<= width; x += 40) {  
for (var y= 0; y \<= height; y += 40)

For var x =0; and var y=0; change zero with other values see what happens

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [May 3, 2023, 6:47pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/5 "2023-05-03T18:47:54Z")

</div>

Hi

Watch this video

[![](https://img.youtube.com/vi/74Ue8z1MHXU/maxresdefault.jpg "p5.js For Loop Tutorial") ](https://www.youtube.com/watch?v=74Ue8z1MHXU)

---

<div class="post-metadata">

### Author: ![Computerscience](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Computerscience](https://discourse.processing.org/u/Computerscience)
#### Post date: [May 3, 2023, 7:07pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/6 "2023-05-03T19:07:16Z")

</div>

Thank so much! I changed your solution a bit so I could fit the question but I got it 🙂

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [May 3, 2023, 7:13pm UTC](https://discourse.processing.org/t/homework-help-with-loops/41903/7 "2023-05-03T19:13:56Z")

</div>

Hi

![Screenshot_2023-05-03-22-10-37-865](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/4/a4b45409eb29c5e9e76ddeacc2736b8dea973fdb.jpeg)
