# The rectangle is moving down the screen! I want the rectangle to stop and start with the Space Bar

**URL:** <https://discourse.processing.org/t/the-rectangle-is-moving-down-the-screen-i-want-the-rectangle-to-stop-and-start-with-the-space-bar/19584>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 9, 2020, 1:44pm UTC](https://discourse.processing.org/t/the-rectangle-is-moving-down-the-screen-i-want-the-rectangle-to-stop-and-start-with-the-space-bar/19584 "2020-04-09T13:44:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)\
**Post date:** [April 9, 2020, 1:44pm UTC](https://discourse.processing.org/t/the-rectangle-is-moving-down-the-screen-i-want-the-rectangle-to-stop-and-start-with-the-space-bar/19584/1 "2020-04-09T13:44:03Z")

</div>

Please help me create this program I have done with the steps of moving rectangle up and down . Just confused with using spacebar for starting and stopping it.

---

<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:** [April 9, 2020, 1:55pm UTC](https://discourse.processing.org/t/the-rectangle-is-moving-down-the-screen-i-want-the-rectangle-to-stop-and-start-with-the-space-bar/19584/2 "2020-04-09T13:55:50Z")

</div>

The Space Bar could switch a boolean variable named moving to true or false.

**Set the variable**

```auto
if(key==' ') 
     moving = ! moving; // The "!" means "not", so we toggle moving here

```

**Evaluate the variable**

Then evaluate this variable moving to move the rectangle or not :

```auto
if(moving) 
    y = y + 3;

```

**Declare the variable**

before setup() say:

`boolean moving=true;`

---

<div class="post-metadata">

**Author:** ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)\
**Post date:** [April 10, 2020, 1:22pm UTC](https://discourse.processing.org/t/the-rectangle-is-moving-down-the-screen-i-want-the-rectangle-to-stop-and-start-with-the-space-bar/19584/3 "2020-04-10T13:22:14Z")

</div>

thanks it really helped:))
