# Why are if AND else being executed at the same time?

**URL:** <https://discourse.processing.org/t/why-are-if-and-else-being-executed-at-the-same-time/8246>\
**Category:** Coding Questions\
**Created:** [February 9, 2019, 4:19pm UTC](https://discourse.processing.org/t/why-are-if-and-else-being-executed-at-the-same-time/8246 "2019-02-09T16:19:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [February 9, 2019, 4:19pm UTC](https://discourse.processing.org/t/why-are-if-and-else-being-executed-at-the-same-time/8246/1 "2019-02-09T16:19:15Z")

</div>

Hi!  
I’m working on a collision system at the moment and everything seemed to work fine (actually not but I want to solve all the other problems on my own lol 😅) but then I realised that a boolean in the code was first set to true - in an if-statement - and then to false - in the associated else statement. WHAT? It’s kinda difficult to show the problem without many lines of code, but I’ll try my best here:

```auto
if(player.x + player.acceleration[2] > x[0] - playerSizeX &&
           player.x - player.acceleration[1] < x[1] + playerSizeX &&
           player.y + player.acceleration[0] >= y[0] - playerSizeY &&
           player.y < y[3] - player.valueForMovingDown[1])
           {
             player.y = y[0] - playerSizeY;
             player.collision[0] = true;
             println("This should not");
           }else{
             player.collision[0] = false;
             println("happen :/");
           }

```

It prints out the whole sentence. As I just showed the segment I’m talking about and didn’t explain anything else, feel free to ask for more code!

---

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [February 9, 2019, 4:47pm UTC](https://discourse.processing.org/t/why-are-if-and-else-being-executed-at-the-same-time/8246/4 "2019-02-09T16:47:11Z")

</div>

I figured it out. There are two “Collision”-object in my ArrayList, and since the player didn’t collide with the second one in the list, that one turned the collision off.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 9, 2019, 5:08pm UTC](https://discourse.processing.org/t/why-are-if-and-else-being-executed-at-the-same-time/8246/5 "2019-02-09T17:08:41Z")

</div>

Glad you figured it out!!

This is a good example of why it is important to provide a minimal, complete, verifiable example – break your problem down into a simpler sketch that actually runs.

> **[How to create a Minimal, Complete, and Verifiable example - Help Center](https://stackoverflow.com/help/mcve)**
>
> Stack Overflow | The World’s Largest Online Community for Developers

In this case, your problem was an outer loop. However, your code fragment didn’t _tell us_ there was an outer loop – so there would have been no way for the forum to investigate your problem or give specific advice on how to fix it. MCVEs take a bit longer to make, but they protect you and the forum from wasting time hunting in the wrong place.

---

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [February 11, 2019, 6:49pm UTC](https://discourse.processing.org/t/why-are-if-and-else-being-executed-at-the-same-time/8246/6 "2019-02-11T18:49:11Z")

</div>

I just really didn’t want to post like a hundred lines of code, but I’ll try to think about what could be important more next time! 😄
