Servo and Ping

I just want an if statement that when there's an object within a certain distance then the servo moves

if (pingRange () < THRESHOLD_DISTANCE) {
  servo.write (POSITION_ONE);
}