>Is there a function or command to do this? Without using a loop.
I don't think so. You will have to write the loop, or use some other workaround.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)