user54046: I have a problem on how to keep my stepper motor moving when button is released. It should only stop moving if I press the button again.
For now, stepper motor  is only moving IF the button is constantly pressed.
//Constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int dirPin = 8;        // the number of the motor direction pin
const int stepPin = 9;         // the number of the motor step pin

//Variables will change:
boolean flag = true;
int buttonState = 0;         // variable for reading the pushbutton status
int distance = 0;   

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(dirPin, OUTPUT);  //YELLOW
  pinMode(stepPin, OUTPUT); //ORANGE

  digitalWrite(buttonPin, LOW);
  digitalWrite(dirPin, HIGH);
  digitalWrite(stepPin, HIGH);
}

void loop() {
  buttonState = digitalRead(buttonPin); // Read the state of the pushbutton 

  if (digitalRead(buttonPin) == LOW) {  // If pushbutton is pressed, buttonState is HIGH:
    digitalWrite(ledPin, HIGH);
    digitalWrite(dirPin, LOW);          // LOW=FORWARD DIRECTION
    digitalWrite(stepPin, HIGH);        // stepPin = MOTOR ON/OFF
    delayMicroseconds(100);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(100);
    distance++;
    if(distance > 21000){
      distance = 0;
      delay (3000);
      reverse();
    }
  } 

  if (digitalRead(buttonPin) == HIGH){ // turn LED off:
    digitalWrite(ledPin, LOW);
    digitalWrite(dirPin, LOW);  //LOW = FORWARD DIRECTION
    digitalWrite(stepPin, LOW); //stepPin = MOTOR ON/OFF
    delayMicroseconds(100);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(100);
  }
}

void reverse() {
  digitalWrite(dirPin,HIGH); //HIGH = REVERSE DIRECTION
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(100);
  distance++;
    if(distance > 21000){
      distance = 0;
      delay(3000);
      return;
    }
  reverse();   
}


user20533: N.b. your code is unreadable, so I won't attempt to debug your program, but I will present some pseudo-code that could help.

It should only stop moving if I press the button again ... [as of] now, [the] stepper motor is only moving IF the button is constantly pressed.

So what you need to do is save the state of your Motor, (MOVING, STOPPED, etc.) and base your code on that state.
You will also need to de-bounce your switch.
Your loop will have to:

Read & de-bounce the switch
Update the state based on switch
Run the stepper based on state

pseudo-code:
// include libraries etc.
#include <Stepper.h> 

// set up your buttons pins etc.
int button = <pin>;
Stepper = step(...); // pins etc.

void setup()
{
   // do setup stuff...
}

enum MOTORSTATES {
  STOPPED = 1,
  FORWARD = 2,
}

MOTORSTATES state = STOPPED;

// forward declare your functions
bool isPressedDebounce(int pin);
void doStep(Stepper&, MOTORSTATES);
MOTORSTATES changeState(MOTORSTATES);

// loop is now simple
void loop()
{
  if(isPressedDebounce(button))
    state = changeState(state);

  doStep(step, state);
}

// because we have broken our problem into pieces
bool isPressedDebounce(int pin)
{
  // proccess and de-bounce the switch
  // implementation left as exercise for reader
}

void doStep(Stepper& step, MOTORSTATES state)
{
  // based on the state move the stepper
  // implementation left as exercise for reader
  switch(state)
  {
    case STOPPED:
      // DO IT
      break;
    case FORWARD:
      // DO IT
      break;
  }
}

MOTORSTATES changeState(MOTORSTATES state)
{
  // n.b. I used this pattern because it is the beginning of a state machine!
  switch(state)
  {
    case STOPPED:
      return FORWARD;
      break;
    case FORWARD:
      return STOPPED;
      break;
  }
}

I structured the pseudo code such that it contains a simple state machine, and can be easily extended. State machine code is very useful for programming Arduinos! 

54046: <p>I have a problem on how to keep my stepper motor moving when button is released. It should only stop moving if I press the button again.</p>

<p>For now, stepper motor  is only moving IF the button is constantly pressed.</p>

<pre><code>//Constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int dirPin = 8;        // the number of the motor direction pin
const int stepPin = 9;         // the number of the motor step pin

//Variables will change:
boolean flag = true;
int buttonState = 0;         // variable for reading the pushbutton status
int distance = 0;   

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(dirPin, OUTPUT);  //YELLOW
  pinMode(stepPin, OUTPUT); //ORANGE

  digitalWrite(buttonPin, LOW);
  digitalWrite(dirPin, HIGH);
  digitalWrite(stepPin, HIGH);
}

void loop() {
  buttonState = digitalRead(buttonPin); // Read the state of the pushbutton 

  if (digitalRead(buttonPin) == LOW) {  // If pushbutton is pressed, buttonState is HIGH:
    digitalWrite(ledPin, HIGH);
    digitalWrite(dirPin, LOW);          // LOW=FORWARD DIRECTION
    digitalWrite(stepPin, HIGH);        // stepPin = MOTOR ON/OFF
    delayMicroseconds(100);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(100);
    distance++;
    if(distance &gt; 21000){
      distance = 0;
      delay (3000);
      reverse();
    }
  } 

  if (digitalRead(buttonPin) == HIGH){ // turn LED off:
    digitalWrite(ledPin, LOW);
    digitalWrite(dirPin, LOW);  //LOW = FORWARD DIRECTION
    digitalWrite(stepPin, LOW); //stepPin = MOTOR ON/OFF
    delayMicroseconds(100);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(100);
  }
}

void reverse() {
  digitalWrite(dirPin,HIGH); //HIGH = REVERSE DIRECTION
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(100);
  distance++;
    if(distance &gt; 21000){
      distance = 0;
      delay(3000);
      return;
    }
  reverse();   
}
</code></pre>
 20533: <p>N.b. your code is unreadable, so I won't attempt to debug your program, but I will present some pseudo-code that could help.</p>

<blockquote>
  <p>It should only stop moving if I press the button again ... [as of] now, [the] stepper motor is only moving IF the button is constantly pressed.</p>
</blockquote>

<p>So what you need to do is save the state of your Motor, (MOVING, STOPPED, etc.) and base your code on that state.</p>

<p>You will also need to de-bounce your switch.</p>

<p>Your loop will have to:</p>

<ul>
<li>Read &amp; de-bounce the switch</li>
<li>Update the state based on switch</li>
<li>Run the stepper based on state</li>
</ul>

<p>pseudo-code:</p>

<pre><code>// include libraries etc.
#include &lt;Stepper.h&gt; 

// set up your buttons pins etc.
int button = &lt;pin&gt;;
Stepper = step(...); // pins etc.

void setup()
{
   // do setup stuff...
}

enum MOTORSTATES {
  STOPPED = 1,
  FORWARD = 2,
}

MOTORSTATES state = STOPPED;

// forward declare your functions
bool isPressedDebounce(int pin);
void doStep(Stepper&amp;, MOTORSTATES);
MOTORSTATES changeState(MOTORSTATES);

// loop is now simple
void loop()
{
  if(isPressedDebounce(button))
    state = changeState(state);

  doStep(step, state);
}

// because we have broken our problem into pieces
bool isPressedDebounce(int pin)
{
  // proccess and de-bounce the switch
  // implementation left as exercise for reader
}

void doStep(Stepper&amp; step, MOTORSTATES state)
{
  // based on the state move the stepper
  // implementation left as exercise for reader
  switch(state)
  {
    case STOPPED:
      // DO IT
      break;
    case FORWARD:
      // DO IT
      break;
  }
}

MOTORSTATES changeState(MOTORSTATES state)
{
  // n.b. I used this pattern because it is the beginning of a state machine!
  switch(state)
  {
    case STOPPED:
      return FORWARD;
      break;
    case FORWARD:
      return STOPPED;
      break;
  }
}
</code></pre>

<p>I structured the pseudo code such that it contains a simple state machine, and can be easily extended. State machine code is very useful for programming Arduinos! </p>
