How can you prevent that? When you are travelling abroad, don't forget that drinking another country's water can be dangerous. Stick with bottled or boiled water and carbonated soft drinks. Remember that the ice in your drink turns into water, so order them without ice, you don't know what might be in the ice.
Wipe off the tops of cans before you drink from them, or better yet, bring some straws to use for drinking. Avoid raw foods, as they can also be a good way to get sick.
So What About Traveler’s Diarrhea While Travelling Abroad? Gallery Photos
So What About Traveler’s Diarrhea While Travelling Abroad?
And keep away from meats that might not be properly cooked or which could be of a poor quality, as they could make you unwell, especially if from animals prone to parasites and toxins building up inside them.
If you are in a country or place with dubious quality of water, then brush your teeth with bottled water and keep your mouth shut when you're in the shower, even an accidental spray could get you sick. And if the water might be contaminated for drinking and there is no bottled water, then if you take some iodine with you, a few drops of that in the water will help to negate any nasties in there.
It is not nice to get ill while on holiday, but by staying careful you can avoid serious problems and still enjoy your travels.