This is a case of structuring your code to deal with looping back to the start of the game. This was something I initially struggled with when I first started making games, as I was just trying to sort the game play out, but is now something I code at the very beginning, putting in all the various sub-routines and functions to deal with menus, loading and deleting media as appropriate, playing the game and the game over state (win or lose).
gosub _basic_setup
gosub _udt_arrays
gosub _intro_screen
rem main loop
do
gosub _load_main_menu_media
gosub _main_menu_loop
gosub _delete_main_menu_media
gosub _load_game_media
gosub _initial_game_values
rem game loop (this could have gone in its own subroutine)
repeat
gosub _screen_fps
gosub _controls
gosub _move_car
gosub _position_camera
gosub _timer
gosub _update_hud
sync()
until game_state = game_state_over
gosub _game_over_screen
gosub _delete_all_media
gosub _update_records
loop
The code above just shows the basic over view of the program structure from one of my games, a simple racer. The variable "game_state" controls when to move on to the next stage of the program. So in the main menu loop, there'll be a condition looking for game_state = game_play in order to exit the menu.
One thing you have to remember is to reset any flags or values that changed over the course of the game. It might that there's something in you program that needs to be reset in order for the game to run properly.
Decision you have to make are whether you want to the player to go through the main menu to replay the game or if you want to just reset the level. Whether you want to delete and reload menu media separately from the game media (as in the above example) or if you want to just load everything on and leave it alone.
You might want to add in something that deletes any "residual" media when the player quits the game.
Whether you use subroutines or functions makes no different to the basic order of things. I just prefer subroutines.