Voltaire's aim in Candide is to disprove the philosopher Leibniz's optimism. This held that our world is the best of all possible worlds and also suggests that any tragedies in this world in some way work toward some greater good. Voltaire believed there was simply too much corruption, hardship, and tragedy in the world around him to justify such a positive perspective. In Candide, Voltaire has his title character travel across continents and experience the foibles of multiple societies in order to prove that this "best of all possible worlds" simply does not exist.
Pangloss, the young Candide's tutor and thus his only source of education, is meant as a caricature of Leibniz. Throughout the novel, Pangloss repeats his belief that we live in the best of all possible worlds, regardless of circumstances that seem to show quite the opposite. Pangloss himself suffers tremendously and sees others die and suffer needlessly, but he blindly repeats his philosophy independent of those events. Candide, for a time, also repeats this philosophy, but he eventually matures a bit through both what he witnesses firsthand and through his exposure to another philosopher, Martin, who is a pessimist (but in the world of the novel, seems to have a much more reasonable take on the world than does Pangloss). At the end of the novel, Pangloss is still spouting his theory, but Candide has changed his tune: he now only wants to "tend the garden," believing that productive work in the only way to function in this nonsensically violent and corrupt world. Candide learns that "the best of all possible worlds" does not exist, so it may be best to avoid the outside world as much as possible.