Why do we have pain?

Last time I wrote about how the brain controls pain. But why would the brain need a system to control pain? The answer is that although pain is unpleasant (at best!), it is often a valuable warning...