Sequencing of my programme

Hi guys, i have a question here.

The code below is on the sequence of displaying a text and then sounding a buzzer. However, what i keep experiencing is that my buzzer always sound first instead of displaying the text. The programme will wait until it finishes the for loop before it displays the text.

Does anyone can help with this problem? Thanks a lot.

if (UGVSelect == 1 && UGVAction == 's') // send UGV
  {
    sendUGV();

    sprintf(UGVLocation1, "Table %d", tableSelect); // print out location status 1
    locationStatus1.setData(UGVLocation1); // change location status to UGV current location
    locationStatus1.setColor(LIGHT_BLUE);

    for ( int i = 0; i < 20; i++)
    {
      digitalWrite(buzzerPin, HIGH);
      delay(50);
      digitalWrite(buzzerPin, LOW);
      delay(50);
    }
    
    UGVAction = 'n';
  }

calai:
Does anyone can help with this problem? Thanks a lot.

Not without seeing your complete program.

A wild guess is that the sendUGV() function (whatever that does) is a non-blocking function and the program moves straight on to the buzzer code.

...R

Apology for the lack of information. This is the code of the sendUGV() function.

void sendUGV() {
  motorBL->run(FORWARD); // turn it on going forward
  motorBR->run(FORWARD);
  motorFL->run(FORWARD);
  motorFR->run(FORWARD);
  delay(delayTime);

  motorBL->run(RELEASE); // stop
  motorBR->run(RELEASE);
  motorFL->run(RELEASE);
  motorFR->run(RELEASE);
}

Robin2:
Not without seeing your complete program.

A wild guess is that the sendUGV() function (whatever that does) is a non-blocking function and the program moves straight on to the buzzer code.

...R

What does non-blocking function means?

A function that uses delay blocks further execution of the program till the delay is finished. A function that uses e.gwhile(digitalRead(somePin) == LOW);blocks further execution of the program till the pin goes HIGH.

Your code uses delay in sendUGV but only you and God know what delayTime is. That's why we ask for complete code or representative example and don't like for snippets.