Real-time clock sensitive while loop

Hi everyone

I am working on realising af specific experiment. I want the information of how long time a particular distance is A compared to B at different time intervals. For this, I am using a proximity sensor which is no problem to program for the task of measure the distance.

Do anyone know how to structure a code for this purpose?

The solution you imply in the title is not the way to go. You simply use the existing loop() and include 'real time clock sensitive' if statements within it.

loop() {
   if (   ) {
       // do something 
   }

 . . .

}