want to get output only one time

I am receiving message using rf 433mhz. But I am receiving an repeating infinite messages on serial monitor, but I want only two message on serial monitor. What should be added to code for this.

transmitter code

#include <VirtualWire.h>

int ObstaclePin = 7;  // This is our input pin
int Obstacle = HIGH;  // HIGH MEANS NO OBSTACLE
const int AOUTpin = 0; //the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
const int DOUTpin = 8; //the DOUT pin of the alcohol sensor goes into digital pin D8 of the arduino



int limit;
int value;
void setup()
{
  pinMode(ObstaclePin, INPUT);
  pinMode(DOUTpin, INPUT);
  Serial.begin(9600);
  vw_set_tx_pin(12); // Pin data
  // Initialize the IO and ISR
  vw_setup(2000); // Bits per sec

}
void loop()
{
  irsensor();

  alcoholsensor();
}

void irsensor()
{
  Obstacle = digitalRead(ObstaclePin);
  if (Obstacle == LOW)
  {
    Serial.println("obstacle absent");
    send("message =Abse");
  }
  else
  {
    Serial.println("obstacle present");
    send("message =Pres");
  }
}
void alcoholsensor()
{
  value = analogRead(AOUTpin); //reads the analaog value from the alcohol sensor's AOUT pin
  limit = digitalRead(DOUTpin); //reads the digital value from the alcohol sensor's DOUT pin
  Serial.print("Alcohol value: ");
  Serial.println(value);//prints the alcohol value
  Serial.print("Limit: ");
  Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
  delay(100);
  if (limit == HIGH) {
    Serial.println("value is less");//if limit has been reached, LED turns on as status indicator
    send("message =Less");
  }
  else {
    Serial.println("value is more");//if threshold not reached, LED remains off
    send("message =More");
  }
}

void send (char *message)
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // Wait until the whole message has gone

}

Receiver code

/*
  2 SimpleReceive
  3 This sketch displays text strings received using VirtualWire
  4 Connect the Receiver data pin to Arduino pin 11
  5 */
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
int Led = 13;
void setup()
{
  Serial.begin(9600);
  Serial.println("Device is ready");
  // Initialize the IO and ISR
  vw_set_rx_pin(11);
  vw_setup(2000); // Bits per sec
  vw_rx_start(); // Start the receiver
  pinMode(Led, OUTPUT);


}
void loop()
{
  if (vw_get_message(message, &messageLength)) // Non-blocking
  {
    Serial.print("Received: ");
    for (int i = 0; i <= messageLength; i++)
    {
      Serial.write(message[i]);

    }
    Serial.println();

  }
}

I want only two message on serial monitor. What should be added to code for this.

Declare a boolean variable as true and only output to the Serial monitor when the variable is true. When your conditions to stop the output are true change the variable to false.

I don't want to receive messages again and again ,I only want the two messages to receive ,not further more. Can I do by any other method?

Is it the serial output that you want to stop or the sending of the message from the transmitter ?

Either way, you can use the method that I suggested. A boolean variable set to true when you want to do something and false when you don't would allow you to conditionally execute the code.

Which two messages are you talking about ?

Is it the serial output that you want to stop or the sending of the message from the transmitter ?

I want to stop the sending of the message of the transmitter.

Which two messages are you talking about ?

The two messages are of two sensors values that I am sending using the transmitter.

I want to stop the transmitter after sending the values of both sensors to the receiver.

I want to stop the transmitter after sending the values of both sensors to the receiver.

As I suggested in reply #1, declare a boolean variable as true and only output the values when the variable is true. When your conditions to stop the output are true change the boolean variable to false.