Using a Generator and Next Function
Python
In this example we have a generator which yields even numbers between two limits. Consecutive even numbers are output each time the generator is passed to the "next" function.
1| def get_even_numbers(lower_limits,upper_limit): 2| for i in range(lower_limits,upper_limit): 3| if i % 2 == 0: 4| yield i 5| even_numbers_under_100 = get_even_numbers(1,100) 6| 7| next(even_numbers_under_100) 8| >> 2 9| 10| next(even_numbers_under_100) 11| >> 4
142
127
122
115