Need Help with HC-SR04 (Ultrasonic Sensor)

Why not call the ranging method once per loop and store the result for your comparisons?