Implemented forEach using next method