Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    There's no point in calling iter between calls to printIter; you can simply pass fruit directly.
    – chepner
    Commented Mar 30, 2020 at 17:15
  • definitely, and since OP has control over printIter() it is probably best to scrap the idea of iterators
    – pastaleg
    Commented Mar 30, 2020 at 17:18
  • Hi @chepner and @pastaleg, I don't have access to iter and fruit directly due to abstraction, I can only call a function to return iter, then use the iterator. Commented Mar 30, 2020 at 18:04
  • Hey @JesujobaALABI, I updated the answer to suggest a conversion to a list.
    – pastaleg
    Commented Mar 30, 2020 at 18:37
  • @juanpa.arrivillaga heavy handed indication of intent. If I try to use that variable later I will get better error message .
    – pastaleg
    Commented Mar 30, 2020 at 19:22