Keep RTC time in a loop I recently started a project with HC-SR04 sensors and RTC DS1302 clock. The idea is when a sensor detects an object, call and keep a timestamp (hh:mm:ss) all over the loop until Else If{} appears,  but I don't know how to.

#include &lt;DS1302.h&gt;
#include &lt;Time.h&gt;
#include &lt;TimeLib.h&gt;
#define echoPin 12 // Echo Pin
#define trigPin 13 // Trigger Pin

time_t t = now();
DS1302 rtc(6,20,21);
String inTime;

void setup()
{
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop(){
    long duration, distance;
    digitalWrite(trigPin, LOW);  
    delayMicroseconds(2); 
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); 
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;

   if (distance &lt;= 4) { 
    inTime= rtc.getTimeStr();
    Serial.println(inTime);

    } 

    else if (distance &gt;= 5 || distance &lt;= 0){
    Serial.println("Out of range");

    }

  delay(500);
}


Appreciate any help, thanks.
Check '{' and '}' pairs in your code.

void loop(){
    long duration, distance;
    digitalWrite(trigPin, LOW);  
    delayMicroseconds(2); 
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); 
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance &lt;= 4) { 
        inTime= rtc.getTimeStr();
        Serial.println(inTime);

   } 
} //&lt;--- what is this little fella doing here?
    else if (distance &gt;= 5 || distance &lt;= 0){
    Serial.println("Out of range");
    }

delay(500);
}