If a Jew goes to the prayer or study hall and doesn't pray or study, he will still get merit for having gone. This is true, even though he does not receive merit for praying or studying.
Why is this so? If he comes, even if not for the right reason, he may be influenced and next time he will come for the right reason.
This is why we should do a mitzvah even if we do not have full and proper intentions. Doing a mitzvah with even less than full intention may very well bring us to do it with the proper intention next time.
What is an example of less than proper intention? For instance, someone does a mitzvah because he is afraid if he doesn't do it he will be punished.
And what is a proper intention? You do the mitzvah because you love the One Who commands us to do it, and you want to please the One you love.