Implementation of foreach