🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Iterators and Generators: all 10 questions

Quiz: Iterators and Generators · Question 3 of 10

Which exception tells a for loop that an iterator has no more values?

Which exception tells a for loop that an iterator has no more values?

  1. A.IndexError
  2. B.ValueError
  3. C.StopIteration
  4. D.EOFError
Answer & explanation

Correct answer: StopIteration

next() raises StopIteration, and the for loop catches it and stops.

Can you get the rest right without peeking?

Take the timed Quiz: Iterators and Generators quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →