Hamlet's famous "To be or not to be" soliloquy in Shakespeare's Hamlet (Act 3.1) is not primarily about suicide. The words to be mean to exist. Hamlet is pondering the question of existence. He's wondering whether or not existence is worth while.
Suicide only comes in to play because that happens to be one of the ways a person can end existence. He mentions suicide while he is making an analogy or giving an example.
Basically, Hamlet decides existence is not worth the trouble, but the alternative is too scary. The alternative, of course, is the unknown afterlife. Were it not for the unknown afterlife, existence would not be worth the trouble.
Hamlet comes down on the side of existence, in the end, because he doesn't know what lies on the other side of death.
Hamlet is asking himself whether he should just kill himself now or whether he should avenge his father's death. Hamlet is philosophical in his thoughts, and they lead him to the next question of whether there is life after death. He wonders if death is like sleeping and having dreams or perhaps there's more to it. His conundrum of "to be or not to be" reflects Hamlet's question of whether it would be better for him to suffer now or suffer later.
Hamlet chooses to get revenge against the king for killing his father. It takes him a while to make the decision, but he goes through with it and dies in the end, along with his mother, the king, Ophelia, and her father.
At the end of his soliloquy, he makes it very clear that his answer is that he cannot kill himself:
Thus the native hue of resolution/ Is sicklied o'er with the pale cast of thought
He is essentially saying, "Clearly I am getting slowed down because I have to think so much about this idea and whether or not suicide is worth it, given that it is both a mortal sin and leads to an afterlife 'from whose bourn no traveller returns' to tell us what it is like, so it is plenty scary."
In "los[ing] the name of action," Hamlet decides that he cannot go through with his plan to kill himself and will instead continue to exist. He continues to struggle with why he should exist, though as the previous answers make clear, he eventually decides that he ought to kill Polonius to avenge his father's death.