the game loop is an infinite loop that starts on line that keeps iterating for as long as the game is in progress remember that the game loop handles eventsupdates the game stateand draws the game state to the screen the game state for the memory puzzle program is stored in the following variablesmainboard revealedboxes firstselection mouseclicked mousex mousey on each iteration of the game loop in the memory puzzle programthe mouseclicked variable stores boolean value that is true if the player has clicked the mouse during this iteration through the game loop (this is part of keeping track of the game state on line the surface is painted over with the background color to erase anything that was previously drawn on it the program then calls drawboard(to draw the current state of the board based on the board and --revealed boxes|data structures that we pass it (these lines of code are part of drawing and updating the screen remember that our drawing functions only draw on the in-memory display surface object this surface object will not actually appear on the screen until we call pygame display update()which is done at the end of the game loop on line the event handling loop k_escape) for event in pygame event get()event handling loop if event type =quit or (event type =keyup and event key =pygame quit(sys exit(elif event type =mousemotionmousexmousey event pos elif event type =mousebuttonupmousexmousey event pos mouseclicked true the for loop on line executes code for every event that has happened since the last iteration of the game loop this loop is called the event handling loop (which is different from the game loopalthough the event handling loop is inside of the game loopand iterates over the list of pygame event objects returned by the pygame event get(call