state doing so makes the while statement simpler because no comparison is made in the while statement itselfthe logic is taken care of in other parts of the program as long as the active variable remains truethe loop will continue running in the if statement inside the while loopwe check the value of message once the user enters their input if the user enters 'quitwwe set active to falseand the while loop stops if the user enters anything other than 'quitxwe print their input as message this program has the same output as the previous example where we placed the conditional test directly in the while statement but now that we have flag to indicate whether the overall program is in an active stateit would be easy to add more tests (such as elif statementsfor events that should cause active to become false this is useful in complicated programs like games in which there may be many events that should each make the program stop running when any of these events causes the active flag to become falsethe main game loop will exita game over message can be displayedand the player can be given the option to play again using break to exit loop to exit while loop immediately without running any remaining code in the loopregardless of the results of any conditional testuse the break statement the break statement directs the flow of your programyou can use it to control which lines of code are executed and which aren'tso the program only executes code that you want it towhen you want it to for exampleconsider program that asks the user about places they've visited we can stop the while loop in this program by calling break as soon as the user enters the 'quitvaluecities py prompt "\nplease enter the name of city you have visited:prompt +"\ (enter 'quitwhen you are finished while truecity input(promptif city ='quit'break elseprint(" ' love to go to city title("!" loop that starts with while true will run forever unless it reaches break statement the loop in this program continues asking the user to enter the names of cities they've been to until they enter 'quitwhen they enter 'quit'the break statement runscausing python to exit the loopplease enter the name of city you have visited(enter 'quitwhen you are finished new york ' love to go to new yorkuser input and while loops