# Need help with this Loop

**URL:** <https://discourse.processing.org/t/need-help-with-this-loop/18256>\
**Category:** Beginners\
**Created:** [February 29, 2020, 9:54pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256 "2020-02-29T21:54:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [February 29, 2020, 9:54pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/1 "2020-02-29T21:54:36Z")

</div>

Can anyone tell me what I am doing wrong? I cannot get this to do more than one row.

```auto
float randomW;
float randomH;
float row;
float column;

void setup(){
size(400,400);
background(250,250,0);
   
for(int row = 0; row<height; row=row+20)
{
  for(int column = 0; column<width; column=column+20);
  {
randomW = random(5,10);
randomH = random(5,10);

  fill(random(0,256), random(0,256), random(0,256));
  rect(row, column, randomW, randomH);
  }}
}

```

---

<div class="post-metadata">

**Author:** ![commie630](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@commie630](https://discourse.processing.org/u/commie630)\
**Post date:** [February 29, 2020, 10:00pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/2 "2020-02-29T22:00:38Z")

</div>

Format your code… maybe in

```auto
rect(row, column, randomW, randomH);

```

you can do

```auto
rect(row * 50, column * 50, randomW, randomH);

```

Also, in your loops

```auto
for(int row = 0; row<height; row=row+20){
    for(int column = 0; column<width; column=column+20);{
    }
}

```

you could use row += 20 and column += 20

---

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [February 29, 2020, 10:19pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/3 "2020-02-29T22:19:09Z")

</div>

I tried your suggestions, but it didn’t change. I need it to reproduce and fill the screen with 20 rows / columns. I really thought I coded it right, but clearly I didn’t because it only produces 1 row. Thank you so much for trying to help me.

---

<div class="post-metadata">

**Author:** ![commie630](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@commie630](https://discourse.processing.org/u/commie630)\
**Post date:** [February 29, 2020, 10:22pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/4 "2020-02-29T22:22:26Z")

</div>

Oh I think the glaring error is the lack of a draw function… put all of your code after size(400, 400) in a

```auto
void draw(){
}

```

function so it refreshes every frame

---

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [February 29, 2020, 10:30pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/5 "2020-02-29T22:30:19Z")

</div>

Thank you for catching that. I changed it, and now you can tell that it is looping because all of the rectangles are flashing, but they are still creating only one row at the top.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [February 29, 2020, 10:38pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/6 "2020-02-29T22:38:45Z")

</div>

```auto
float randomW;
float randomH;
float row;
float column;

void setup() {
  size(400, 400);
}

void draw() {
  background(250, 250, 0);
  for (int row = 0; row<height; row+=20) {
    for (int column = 0; column<width; column+=20) {
      randomW = random(5, 10);
      randomH = random(5, 10);
      fill(random(0, 256), random(0, 256), random(0, 256));
      rect(row, column, randomW, randomH);
    }
  }
}

```

You had a stray semicolon here:

```auto
 for(int column = 0; column<width; column=column+20);{

```

See it? Right near the end, between the ) and {?  
That ruins the structure of your code, essentially making your column loop do nothing.

---

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [February 29, 2020, 10:40pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/7 "2020-02-29T22:40:34Z")

</div>

That worked!!! Oh my gosh!!! Thank you so much!!!

---

<div class="post-metadata">

**Author:** ![GKBeginner](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@GKBeginner](https://discourse.processing.org/u/GKBeginner)\
**Post date:** [February 29, 2020, 10:57pm UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/8 "2020-02-29T22:57:03Z")

</div>

Is there any way you could look at another problem I am having?

Cant get this to stop at 25 ellipses.

```auto
float randomX;
float randomY;
float randomZ;
float randomQ;
int x;

void setup(){
  size(400,400);
  background(250,250,0);   
}
void draw(){
randomX = random(width);
randomY = random(height);
randomZ = random(10,50);
randomQ = random(10,50);

    for (x = 0; x<25; x++)
     
  fill(random(0,256), random(0,256), random(0,256));
  ellipse(randomX, randomY, randomZ, randomQ);
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 1, 2020, 2:14am UTC](https://discourse.processing.org/t/need-help-with-this-loop/18256/9 "2020-03-01T02:14:27Z")

</div>

And where’s the curly brace to start this for loop? {?
