Is this the best aproach?

This is only part of the code. I want the Detection_mode function to loop continuously once it’s called in the void loop. would this be the best approach to keep the detection_mode funtion looping, instead of repeating all the functions in the void loop?

I’m using 3 LV Maxsonar (ultrasonic) sensors and Arduino nano.

void Detection_Mode () {
  int i = true;
  while (i == true) {

    if (distance1 < 20) {
      digitalWrite( vibe1, HIGH);
    } 
    
    else  {
      digitalWrite(vibe1, LOW);
    }
  
  
    if (distance2 < 20) {
      digitalWrite(vibe2, HIGH);
    } 
    
    else {
      digitalWrite(vibe2, LOW);
    }
    
    if (distance3 < 20) {
      digitalWrite(Buzzer, HIGH);
  
    } 
    
    else {
      digitalWrite(Buzzer, LOW);
    }
  }
}
  
void loop() {
  start_sensor();
  read_sensors();
  print_all();
  Detection_Mode();
  delay(150); 
}

I want the Detection_mode function to loop continuously once it's called in the void loop.

So how will the values of your distance variables ever change ?

Question is which problem you're trying to solve.

In general, there is no place / need for for-loops and while-loops in Arduino code as that can be handled by loop(). There are obviously exceptions but I have some doubts that that will be the case in your scenario.

Akuregian:
This is only part of the code. I want the Detection_mode function to loop continuously once it's called in the void loop. would this be the best approach to keep the detection_mode funtion looping,

If you have a WHILE in a function the control will not return to loop() until the WHILE completes.

Have a look at the demo Several Things at a Time. Note how each function runs very briefly and returns to loop() so the next one can be called. Long running processes are achieved a tiny piece at a time. And there may be dozens of calls to some functions before it is actually time for anything to happen.

...R

Do you really want to stay in that code, which doesn't read the sensors, and keep checking the unchanging sensor values for ever and ever? It seems like a strange ambition.

Steve