In 2011, I visited a LDS church. On my visit, I noticed that bread and water were served. At the time, I merely thought they were some sort of snack for the congregation, and I gladly took a tiny cup of water and a piece of bread. The people didn't seem to care about my taking communion. Does that mean it is okay?
The breaking, blessing, and partaking of the bread and water constitutes the sacrament ordinance in the LDS Church. It's how one renews their baptismal covenants. If one has not made those covenants, it is of no matter. (Parents often encourage their children to take the sacrament to prepare them to one day renew their covenants and to teach them the value of the ordinance. Others discourage it because it has special meaning.)
Either way, the sacrament is not withheld from individuals while being passed, whether they are visitors or not. It is perfectly acceptable for visitors in an LDS congregation to partake of the sacrament:
Matt has described the current policy of the LDS church accurately - namely, that nobody in attendance should be discouraged from taking of the sacrament. For informational purposes, however, it is useful to know that his policy was enacted following years of fairly inconsistent practices from congregation to congregation. As the LDS Church has grown globally, its leaders have clarified certain policies to accomplish international consistency.
Bearing both the previous answer and this one in mind give a broad view of the official policy, while explaining why individual discrepancies arise.