In the days of muzzle-loading muskets it was most frequently used to refer to the first wave of soldiers attacking a breach in defences during a siege. It was likely that most members of the forlorn hope would be killed or wounded. The intention was that some would survive long enough to seize a foothold that could be reinforced, or at least that a second wave with better prospects could be sent in while the defenders were reloading or engaged in mopping up the remnants of the first wave.
A forlorn hope was typically led by a junior officer with hopes of personal advancement. If he survived, and performed courageously, he was almost guaranteed both a promotion and a long-term boost to his career prospects. As a result, despite the risks, there was often competition for the opportunity to lead the assault. The French equivalent of the Forlorn Hope, called Les Enfants Perdus or The Lost Children, were all guaranteed promotion to officers should they survive, and on both sides men took up the suicidal mission as an opportunity to raise themselves in the army.
There was a symmetry between the risks faced by the forlorn hope and those faced by the defenders. Once a breach suitable for assault had been made in the walls, defenders were usually given a chance to surrender safely. The defenders had already shown their determination and there would be no loss of honour in surrender. If however they chose not to take this opportunity, forcing the attackers to undertake an assault, the usages of war made them subject to massacre, and made the position (often a town or city) that they were holding subject to being sacked and pillaged (see looting) as described by Shakespeare's Henry V before the walls of Harfleur:
By extension, the term forlorn hope became used for any body of troops placed in a hazardous position; e.g. an exposed outpost, or the defenders of an outwork in advance of the main defensive position. This usage was especially common in accounts of the English Civil War, as well as in the British Army in the Peninsular War of 1808-1814.