David fletcher - "You will also need to update the distance within the while loop, otherwise the loop would never end (if it was initially entered). What is the value of distance returned from the sensor (your use of any(distance....) suggests that it's a vector rather than a scaler value?"
I did not update the distance measurement within the while loop, just like David mentioned, after rewriting it, it now works as intended (I should have also initially provided more information) - thanks for the help!