replacing a while with a for with splats