Simple Light sensor programming

I've been playing around with printing the status of a light sensor to the serial monitor. It displays two very basic things: 'sensor open', the sensor senses light, and 'sensor blocked', the sensor is blocked or is not sensing any light. I just need one small thing added to the code that I have not been able to figure out. When the program prints the status of the light sensor, it prints 'sensor open' continuously until the sensor is blocked, and then it prints 'sensor blocked' continuously. Like this:

sensor open
sensor open
sensor open
sensor open
sensor blocked
sensor blocked
sensor blocked
sensor blocked
sensor blocked
sensor open
sensor open
sensor open

I want it to be print 'sensor open' once, and the when the sensor is blocked, 'sensor blocked' only once until the sensor is open once again. Then the serial monitor would look more like this:

sensor open
sensor blocked
sensor open
sensor blocked

If you understand what I mean, help would be really appreciated. I'm really new to the programming aspect of the Arduino.

Here is my code:

int lightPin = 0; //PhotoResistor Pin
int ledPin = 13; // Led Pin


void setup()
{
  
  pinMode(ledPin, OUTPUT); //sets the led pin to output
  digitalWrite(ledPin, HIGH); //turns on led
  Serial.begin(9600);
}

void loop()
{
  int threshold = 300;
if (analogRead(lightPin) > threshold)
 
 {
   Serial.println("sensor blocked");
   delay(50);
   
 }else{
  Serial.println("sensor open");
   delay(50);
  }}

In the very beginning of the code you could initiate two settings, then in your setup determine the initial value of the first setting by reading the sensor and then in your loop only have it print to the serial monitor if that setting's value is different than the last one.

Kind of like this;

look at this part:
int buttonState = 0;
int lastButtonState = 0;

Try this:-

int lightPin = 0; //PhotoResistor Pin
int ledPin = 13; // Led Pin
boolean sensorState = false;

void setup()
{

  pinMode(ledPin, OUTPUT); //sets the led pin to output
  digitalWrite(ledPin, HIGH); //turns on led
  Serial.begin(9600);
}

void loop()
{
  int threshold = 300;
if (analogRead(lightPin) > threshold && sensorState == true)

 {
   Serial.println("sensor blocked");
   sensorState = false;
   delay(50);

 }else{
   if(sensorState == false){
  Serial.println("sensor open");
  sensorState = true;
   delay(50);
   }
  }}