geeksforgeeks iterate simple method