Countries with mandatory military service prevent their citizens / conscripted residents from freely leaving, to varying extents.
That's a bit of a broadly brushed statement... Switzerland doesn't prevent you from leaving, you just need to make sure you've told the military before you do so (so that you don't get invited to do service when you're abroad). The mandatory military service only applies to resident citizens, and not to those living abroad. You're free to move as you want.
Of course if you come back you'll need to complete the same service everyone else does. However if you don't complete bootcamp by age 24 (or possibly 26?) you can't do military service, so you're automatically assigned to one of civilian service or civil defence (not quite sure what the algorithm is, but civilian service tends to be for conscientious objectors, civil defence is for those not capable of military service).