I am wondering how to break out of the while loop if the distance is <=3. if the if statements distance is <=3 within the while loops if statement block, will this end the entire while loop? I tried looking this up on many pages but all the answers are very confusing to me.
A break should do it, but I think it is best practice to just design your check in your while loop itself to work without having to use a break, for example in case you change your code later to include nested loops.
In most cases putting the conditional in the loop is the better option.
But sometimes you need something more powerful. break and continue are both useful keywords here. break stops the loop altogether. continue stops the current iteration and jumps to the next one.
If you are really desperate you can use goto. goto is quite powerful if you need to break out of a lot of deeply nested loops.