You wouldn’t really want to use an if statement for this (at least in my opinion). If statements are swell for checking things, but not for waiting to do something.
If you look at post 5 (it was my post), I made a little pseudo code that will drive forward until the distance is traveled (it wasn’t that good, but it probably would have worked).
Copied from post 5:
while (distance traveled is less than target)
{
get rotation;
convert rotation distance to inches using circumference;
drive forward
}
stop driving
I’ll make it a lot closer to operable code but you’ll still need to create some variables, put in motor commands, etc.
encoder.resetRotation();
while ((circumference * (encoder.rotation() / 360)) < target_distance)
{
drive forward
}
stop driving
Hopefully that is enough to get you started!