# What's wrong with this code? HELP I want to code to like the picture I've added of

**URL:** <https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249>\
**Category:** Coding Questions\
**Created:** [June 23, 2019, 11:08am UTC](https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249 "2019-06-23T11:08:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://discourse.processing.org/u/henry)\
**Post date:** [June 23, 2019, 11:08am UTC](https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249/1 "2019-06-23T11:08:44Z")

</div>

```auto
size(300, 300);

int[]data={50, 100, 30, 120, 40, 70, 150};
int max=data[0];
int min=data[0];
for (int i=0; i<data.length; i++) {

    fill(255);
    rect(10+15*i, 10, 10, data[i]);
  if(max<data[i]) {
     max=data[i];
   
    fill(255, 0, 0);
    rect(10+15*i, 10, 10, max);
  
  } 

  if ( min>data[i]) {
    min=data[i];
      
    fill(0, 0, 255);
    rect(10+15*i, 10, 10, min);
  } 
}

```

 ![05](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1d1b43807b633014ff2fa8475baff04df4f338e8.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 23, 2019, 11:17am UTC](https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249/2 "2019-06-23T11:17:50Z")

</div>

You need to run the entire for loop without drawing to set min and max

Then run the 2nd for loop and set fill accordingly to max and min and draw the rect after setting fill

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [June 23, 2019, 11:19am UTC](https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249/3 "2019-06-23T11:19:01Z")

</div>

yes, like

```auto
size(300, 300);
int[]data={50, 100, 30, 120, 40, 70, 150};
int max=-1000, min=1000;

for (int i=0; i<data.length; i++) { // first min max run
  if ( max < data[i]) max = data[i];
  if ( min > data[i]) min = data[i];
}

for (int i=0; i<data.length; i++) { // draw run
  fill(255); // make color 
  if ( max == data[i] ) fill(255, 0, 0);
  if ( min == data[i] ) fill(0, 0, 255);
  rect(10+15*i, 10, 10, data[i]); // draw
}

```

---

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://discourse.processing.org/u/henry)\
**Post date:** [June 23, 2019, 11:27am UTC](https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249/4 "2019-06-23T11:27:52Z")

</div>

Thank you Chrisir! I solved the problem!

---

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://discourse.processing.org/u/henry)\
**Post date:** [June 23, 2019, 11:28am UTC](https://discourse.processing.org/t/whats-wrong-with-this-code-help-i-want-to-code-to-like-the-picture-ive-added-of/12249/5 "2019-06-23T11:28:54Z")

</div>

Thank you so much! kll !  
I solved the problem!
