[NSApp terminate: nil];This is usually done when the user selects the Quit entry in the main menu. When you terminate your application, the gui library quits the run loop and exits the program.
Btw, the argument of terminate: is of no importance, so we can pass any argument (nil in this case); the only reason why this method takes an object as argument is that it can then be set as the action of a gui control (discussed below).