programming of 4wd robot using ping sensor

I already figure out, all I needed to do was to introduce a delay at the end of if. it is working fine now. Thank you