wrap with function inside loops