Dog owners why do dogs eat poop and how to stop it?

One of the most disgusting thing I have ever witnessed happened today when my little johnny starts eating his own poop after I have given him a big bowl of cereal.

On another occassion I found him eating poop from litter box

I wanna know why do dogs eat poop and how do I stop it