Skip to main content
deleted 1 character in body
Source Link
coredump
  • 6k
  • 2
  • 23
  • 30

You can use enumerated types instead of strings, and keep your implementation.

Or, if you don't mind using exceptions you can write:

try:
    for item in items:
        if shall_process(item):
            process_the_item(item)
except StopEverythingStopIteration:
    pass

Here, shall_process returns a boolean and can throw an exception to exit the iteration.

You can use enumerated types instead of strings, and keep your implementation.

Or, if you don't mind using exceptions you can write:

try:
    for item in items:
        if shall_process(item):
            process_the_item(item)
except StopEverything:
    pass

Here, shall_process returns a boolean and can throw an exception to exit the iteration.

You can use enumerated types instead of strings, and keep your implementation.

Or, if you don't mind using exceptions you can write:

try:
    for item in items:
        if shall_process(item):
            process_the_item(item)
except StopIteration:
    pass

Here, shall_process returns a boolean and can throw an exception to exit the iteration.

Source Link
coredump
  • 6k
  • 2
  • 23
  • 30

You can use enumerated types instead of strings, and keep your implementation.

Or, if you don't mind using exceptions you can write:

try:
    for item in items:
        if shall_process(item):
            process_the_item(item)
except StopEverything:
    pass

Here, shall_process returns a boolean and can throw an exception to exit the iteration.