I can just tell you about my own experience, here we go:
If I am honest, my only motivation when doing something is the outcome of it. If I code something, I get paid for it. If I learn, I get a good grade. If I clean my room, my mom stops fucking arguing about it. Get it?
It is the same when I am doing stuff for others, like buying some ice-cream for my brother, letting a friend copy some answers in a test and so on. Studies have proven that you are feeling better when you buy
something for others and they are happy about it, than if you buy something for yourself, which I can approve from my point of view. Like Newton said, every action causes a reaction and so it is happening with
motivation, a bit different but the idea behind it is the same. You do something -> Something happens. I doubt anyone is doing something for the sake of "doing it", if you understand what I mean.