It is safer to swim in water that is well chlorinated, this usually means well maintained swimming pools.
If you are travelling to Africa, the biggest risk is a disease called Schistosomiasis which is also known as Bilharzia or Snail Fever.
Schistosomiasis is a chronic illness that can cause fever, liver problems, pre-dispose to bladder cancer as snail larvae also known as cercariae penetrate through your skin and travel to your liver veins to reproduce.
In addidion to Bilhazia other diseases can also be caught from sand and soil, particularly wet soil and by insect bites.
It is therefore best never to go barefoot on the beach, paddle is fresh water streams and and always wear protective footwear.