Stepper Code - Start Stop

So I am using the Arduino to start a stepper motor to rotate a certain number of steps and then stop. The motor will start depending on when the signal from an input is given. The motor is connected to an EasyDriver.

I am new to coding and despite all the research I did on this, I could only find example codes to make a stepper rotate back and forth for example. I tried understanding what I could from the code on the EasyDriver website and Dan Thompson's stepper tutorials.

The following is the code I am using;

int dirpin = 8;
int steppin = 9;

void setup() {

pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}

void loop()
{

  int i;

  digitalWrite(dirpin, LOW);     // Set the direction.
  delay(2000);

  for (i = 0; i<25; i++)       // Iterate for 25 microsteps.
  {
digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
    delayMicroseconds(200);      // This delay time is close to top speed for this
  }                              // particular motor. Any faster the motor stalls.


}

The code is slightly modified from Dan Thompson's tutorial. The pins are the Direction and Step pins from the EasyDriver.
So, the 25 microsteps are the equivalent of the angle I require the shaft to rotate and the way I understand it is that the iterations will keep rising until they reach that 25.
That being said, the program will rotate the motors shaft the required steps, pause for 2000 milliseconds and rotate again.

I need it to simply rotate those 25 steps and stop, no looping of that rotation!
I am a bit at a loss, Any suggestions?

Thanks,
Al

The loop() function is called in an endless loop, for the for loop will be executed every time. Typically, if you want something done once, you put that code in setup().

You could create a global flag:

bool beenThereDoneThat = false;

Then, in loop:

   if(!beenThereDoneThat)
   {
     digitalWrite(dirpin, LOW);     // Set the direction.
     delay(2000);

     for (i = 0; i<25; i++)       // Iterate for 25 microsteps.
     {
        digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
        digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
        delayMicroseconds(200);      // This delay time is close to top speed for this
     }                              // particular motor. Any faster the motor stalls.

     beenThereDoneThat = true;
   }

I had tried to put it in the setup and for some reason it did not work, the thing is that I'm just going to test this short sketch and then call it in a main loop, I'll try doing what you suggested ASAP.

Cheers