How to make functions which in loop run only once?

void loop() {
      BPM = analogRead(A2);
      BPM = map(BPM,0,1023,40,180);
      BPM1 = 60000/BPM;
      BPM2 = BPM1-BPM;
      Serial.println(BPM);
      char A = bluetooth.read();
      int B = 0;
  if( A = "Tempo ="){
    bluetooth.println(BPM);
    B = B + 1;
  if( B = 1 ){
    B = 0 ;
    }
  }

this is my code's loop. it is a kind of metronome

i want to make some function run like this :

  1. when bluetooth master (android) send the letter "Tempo =" (or anything).

  2. bluetooth slave (arduino) send 'BPM' in code to android only once.

now, i'm using this code. this code send BPM to android every notes.

I know why my arduino send BPM everytime, but i don't know how to change them.

how can i solve this problem?

Use a global variable as a flag to store whether the code has already ran:

if(alreadyRan == false) {
  alreadyRan = true;
  // code you only want to run once
}
char A = bluetooth.read();

   if( A = "Tempo ="){

This will not work and create warning that should be an error.

   if( B = 1 ){
      B = 0 ;
   }

A strange variant of "B = 0;", so why bother to increment B before?

if( B = 1 )

In any case, this is not testing the value of B, rather it is setting it to 1