The usual way to train swimming is to drop dwarves into a room containing 4/7 water, and let them out later (if you remember). This is not a particularly good method.
The best way - designed specifically to train idlers - is to create a long 1-wide mineshaft of water - 20, or 50, or 100 tiles long, which can be a spiral, or folded or whatever you want. Fill it up with 6/7 water - the lazy dwarf's way to do this is to dig out most of the channel, fill it to 7/7 water using a pump, then dig out the the last few tiles, so the water spreads out to a safe depth. Do note that high skill swimmers will escape at any point where there is no ceiling or wall stopping them getting out. Only low-skilled swimmers require a ramp.
Now above one end of swimming shaft, build a retracting bridge, linked to a pressure plate in the corridor leading to the bridge, and place a meeting zone on that bridge. When an idle dwarf comes to the meeting zone, he will step on the plate, and a few moments later the bridge will open, dropping him into the water (the plate should be as close to the bridge as possible).
Now he has to swim to the exit point (which should be very close to the start point). He will then return to the meeting zone and get re-dumped, and keep going round and round as long as he is idle or on break (hurray!).
By making them swim a long, convoluted path back to the start point - but letting them get out by themselves - they'll be training swimming 95% of the time, but will still attend to their needs or jobs.
Of course you can train military in the same way by stationing them on the bridge (but it needs to be a 4 long bridge for that to work).
I think this is probably one of the single best way to cross-train your entire idle workforce, on breakers, children and all.