To end a while loop either the abort condition has to be false or you can end it using a break statement.
You just have to write an if statement or anything else that checks whether the loop should stop and if so you just add a break; and the loop will stop.