# Can you help me repair it?

**URL:** <https://discourse.processing.org/t/can-you-help-me-repair-it/15502>\
**Category:** Coding Questions\
**Created:** [November 15, 2019, 8:30am UTC](https://discourse.processing.org/t/can-you-help-me-repair-it/15502 "2019-11-15T08:30:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soloh](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Soloh](https://discourse.processing.org/u/Soloh)\
**Post date:** [November 15, 2019, 8:30am UTC](https://discourse.processing.org/t/can-you-help-me-repair-it/15502/1 "2019-11-15T08:30:24Z")

</div>

```auto
int x=500;
int o=600;
void setup() {
 size(1000,1000);
 strokeWeight(2);
}

void draw() {
background(100,150,200);
line(500,200,x,700);
ellipse(x,700,200,200);
ellipse(x,700,170,170);
ellipse(x,700,140,140);
ellipse(x,700,100,100);
ellipse(x,700,70,70);
if(x<600){
  x=x+1;}
else if(x==600 || x<500 ){
  x=o;
  o=o-1;
  x=x-1;}
}

```

---

<div class="post-metadata">

**Author:** ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)\
**Post date:** [November 15, 2019, 9:27am UTC](https://discourse.processing.org/t/can-you-help-me-repair-it/15502/2 "2019-11-15T09:27:23Z")

</div>

Good morning Soloh,

Could you please edit your post and format the code? Open your sketch in Processing, click on `Edit / Auto Format`, and copy the formatted code In your post. In your post click on `< /> Preformatted text` and paste it on the right position. The end result should look something like:

```auto
int x=500;
int o=600;
// ...
// rest of your code
// ...
  x = x - 1;}
}

```

About your issue. At the end of `void draw()` you’ve placed an if/else if statement. The problem is that once x is higher than 600 and enters the `else if` part, x gets reduced. This means that in the following draw loop x is lower than 600 again and it enters the `if` again.  
As a result your animation keeps rapidly switching between `if` and `else if` around x = 600. Do you understand now why your issue is happening?

There are several ways to solve this, but if you want to maintain your current structure I’d go for a [boolean](https://processing.org/reference/boolean.html) that keeps track of the swing direction. For instance, if it’s true it should swing to the right, and once it reaches x = 600 it becomes false. Using that value, you could adjust your `else if` conditions.
