The main function is to facilitate the exchange of oxygen and carbon dioxide between the body and the environment.