# How to restrict how far an object can decrease size?

**URL:** <https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600>\
**Category:** Libraries\
**Created:** [September 17, 2018, 2:00pm UTC](https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600 "2018-09-17T14:00:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinM](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MartinM](https://discourse.processing.org/u/MartinM)\
**Post date:** [September 17, 2018, 2:00pm UTC](https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600/1 "2018-09-17T14:00:19Z")

</div>

I currently have a rectangle shrinking its size upon impact with a ball, is there any way I can make sure that once it shrinks to a certain size it stops shrinking and just remains that size?

```
void paddle(PVector pad){;
  if (ballLoc.x +ballsize/2>pad.x -playerW/2&&
  ballLoc.x -ballsize/2<pad.x +playerW/2&&
  ballLoc.y +ballsize/2>pad.y -playerH/2&&
  ballLoc.y -ballsize/2<pad.y +playerH/2){
  speedX *=-1;
  audiosplayer.pause();
  audiosplayer.rewind();
  audiosplayer.play();
  playerH-=5;
 
  
  }
}

```

The second to last line is decreasing height of rectangle each time but I want it to stop after lets say it hits 20. What could I state in the code to do so?

---

<div class="post-metadata">

**Author:** ![Pyrros](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pyrros](https://discourse.processing.org/u/Pyrros)\
**Post date:** [September 17, 2018, 2:27pm UTC](https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600/2 "2018-09-17T14:27:10Z")

</div>

Hi MartinM,  
Have your researched what a `for`-loop is? I think it would be a very nice solution to your problem.

---

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [September 17, 2018, 2:36pm UTC](https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600/3 "2018-09-17T14:36:21Z")

</div>

Hi.  
I guess playerH is your size?  
You have to check your size before shrinking:

```auto
if (playerH > 20) {
  playerH-=5;
}

```

Then you only can shrink if your size is big enough (\> 20 in this case).

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 17, 2018, 2:55pm UTC](https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600/4 "2018-09-17T14:55:23Z")

</div>

`playerH = max(playerH - 5, 20);`

[Processing.org/reference/max\_.html](http://Processing.org/reference/max_.html)

---

<div class="post-metadata">

**Author:** ![MartinM](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MartinM](https://discourse.processing.org/u/MartinM)\
**Post date:** [September 17, 2018, 5:31pm UTC](https://discourse.processing.org/t/how-to-restrict-how-far-an-object-can-decrease-size/3600/5 "2018-09-17T17:31:16Z")

</div>

Thank you I actually had not thought about using a for loop to solve my issue I was rather thinking of just another way to implement the if statement but a for-loop would work wonders
