Car Parking System

can anyone explain the use of flag1 and flag 2?

// Arduino Car Parking System

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  //Change the HEX address
#include <Servo.h> 

Servo myservo1;

int IR1 = 2;
int IR2 = 4;

int Slot = 4;           //Enter Total number of parking Slots

int flag1 = 0;
int flag2 = 0;

void setup() {
  lcd.begin(16,2);
  lcd.backlight();
  pinMode(IR1, INPUT);
  pinMode(IR2, INPUT);
  
  myservo1.attach(3);
  myservo1.write(100);

  lcd.setCursor (0,0);
  lcd.print(" SELAMAT DATANG ");
  lcd.setCursor (0,1);
  lcd.print("  ELOK PARKING  ");
  delay (2000);
  lcd.clear();  
}

void loop(){ 

  if(digitalRead (IR1) == LOW && flag1==0){
    if(Slot>0){flag1=1;
    if(flag2==0){myservo1.write(0); Slot = Slot-1;}
  }
   else{
    lcd.setCursor (0,0);
    lcd.print("    MAAF :(    ");  
    lcd.setCursor (0,1);
    lcd.print(" PARKIRAN PENUH "); 
    delay (3000);
    lcd.clear(); 
  }
}

  if(digitalRead (IR2) == LOW && flag2==0){flag2=1;
    if(flag1==0){myservo1.write(0); Slot = Slot+1;}
  }

  if(flag1==1 && flag2==1){
   delay (1000);
  myservo1.write(100);
  flag1=0, flag2=0;
}

  lcd.setCursor (0,0);
  lcd.print("SELAMAT DATANG!");
  lcd.setCursor (0,1);
  lcd.print("SLOT TERSISA: ");
  lcd.print(Slot);
}

loop() will execute many, many times, but you only want to increment/decrement the available slots 1 time, not every time through loop.

Can you explain why the constants aren't ... constant?

I think flag1 and flag2 are used to determine way the vehicle is going. If a vehicle wants to go in (IR1/flag1 first) it has to wait until a slot is available. If a slot is available when a car tries to go in or a car is trying to go out, the gate is lifted. When the car goes through the gate and triggers the other sensor, the gate is closed.