Servo and Ping

Hi, I'm new to arduino and am currently working with a ping sensor and servo. I can get the ping to work and the servo to work with a potentiometer separately but am having a hard time getting them to work together. I just want an if statement that when there's an object within a certain distance then the servo moves. Does anyone have a base code for this that I can get started with. I already have know about the ones that come with the software, but anything that combines the two that I can edit to fit my needs.

Thanks so much!

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);
}