Honestly, that's the easiest and most effective way to prevent sexually transmitted diseases/infections.
If you choose to have sex, use protection - it won't always be 100% effective (if you don't do it at all, you are not at any risk!), but it'll help prevent diseases/infections more than without protection.