When creating any type of game using only code, the best thing to start with is a game loop. Everything that runs the game at its core usually goes in this loop as indicated in the comments in the below code examples.