my_set = {1, 2, 3, 4, 5} iterator = iter(my_set) while True: try: element = next(iterator) print(element) except StopIteration: break