I need help with functions

Hey guys,
current project is a RFID door.
the door should be opened if a correct RFID token is presented and closed if a button is presented once.
In the Background a Flip-Flop should be triggered so the Motor won't turn too far.
I got a Problem with functions. I want to name a program section, recall it in the main program by its name and execute it for n times. n is a var and will be set.

Program Section 1.: This Program should be called [opendoor]

{
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
digitalWrite(s4, HIGH);
delay(3);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, HIGH);
digitalWrite(s4, LOW);
delay(3);
digitalWrite(s1, LOW);
digitalWrite(s2, HIGH);
digitalWrite(s3, LOW);
digitalWrite(s4, LOW);
delay(3);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
digitalWrite(s4, LOW);
delay(3);
}

Program section 2: closedoor

{
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
digitalWrite(s4, LOW);
delay(3);
digitalWrite(s1, LOW);
digitalWrite(s2, HIGH);
digitalWrite(s3, LOW);
digitalWrite(s4, LOW);
delay(3);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, HIGH);
digitalWrite(s4, LOW);
delay(3);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
digitalWrite(s4, HIGH);
delay(3);
}

Main Program:

#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
int n=120;//motor turning angle
MFRC522 mfrc522(SS_PIN, RST_PIN);
int s1 = A1;
int s2 = A2;
int s3 = A3;
int s4 = A4;
int x;
int y=500;
void setup()
{
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(s4, OUTPUT);

#define IN1 A1
#define IN2 A2
#define IN3 A3
#define IN4 A4
int Steps = 4096;
int cstep = 0;
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();

pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(8,OUTPUT);
}

void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}

if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}

long code=0;

for (byte i = 0; i < mfrc522.uid.size; i++)
{
code=((code+mfrc522.uid.uidByte_)*10);_
}
Serial.print("Die Kartennummer lautet:");
Serial.println(code);
if ((code==1234567)or (code==0000000));
{//opendoor n repetitions
}
if (digitalRead 8 HIGH);
{//closedoor n repetitions}
}
}

You need to read the post stickie at the top of the forum on how to post code !

Do you really mean repetitions or do you mean opendoor 'n' seconds ?

You've almost done what you want... just call it

void opendoor() {

  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  digitalWrite(s4, HIGH);
  delay(3);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, HIGH);
  digitalWrite(s4, LOW);
  delay(3);
  digitalWrite(s1, LOW);
  digitalWrite(s2, HIGH);
  digitalWrite(s3, LOW);
  digitalWrite(s4, LOW);
  delay(3);
  digitalWrite(s1, HIGH);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  digitalWrite(s4, LOW);
  delay(3);
}

then call it

if ((code==1234567)or (code==0000000));
 {
      opendoor();
 }

That will call it once as I'm not sure what you really want.

Thanks for the help.
I really mean repetitions, to set how often the opendoor section is triggered and how many steps the stepper should make and how far the lock turns.
Should I put the declaration part in the Setup or in the loop part?

Why not use the Stepper library instead of hard switching. You should be aware that you shouldn't drive a stepper directly anyway and use a driver board instead.

Look up stepper examples and see how the hardware is connected.