Robert,
The map I'm working with has a large number of child layers. In my mind, I run a for loop like the above to ensure that all child layers are not visible, then just switch the few on for the function required.
This said, I'm starting to dig around with some of the functions and get the feeling that it wont be as simple as an easy modification to the code above. Perhaps loading subLayerIds to an array then looping through them? Thoughts?