boost-style loop function