Dogs are like any other animal – including the human being – in that they will sometimes step over the line of bad behavior in the pursuit of enjoyment or comfort. If you are honest with yourself you must admit that there have been times when you did something wrong because the results of such action had benefits for you. Whether those benefits were active – you took something that was not yours and enjoyed using it – or passive, in that you did not do something because the alternative was preferable to you, you still transgressed.
Dogs are just the same. If a dog has gone to the toilet in the house, for example, it will have done so because it was easier than going outside. There may be many reasons why this was the case, but all the dog knows is that its action was what seemed like the right thing for it. This is not a mode of behavior you would wish to encourage, so you need to consider how to eliminate it in future. The best way of doing this may be to scold the dog sternly, or deprive it of its favorite toy – the important thing is to establish a link between action and outcome.
If a dog goes to the toilet in the house, there is little point in going to find the dog and handing out punishment there and then. The dog will not connect the punishment with the action. You need to establish this firm link by taking the dog to the scene of the action, and making clear your displeasure. Only then will the dog link cause and effect.