Skip to content

for-else #337

Description

@pauldraper

I am once again asking for for-else loops.

has_ts = False
for file in files:
    if file.endswith(".d.ts"):
        has_ts = True
        break
if not has_ts:
    # TODO
    pass

Whereas this can be much more succient.

for file in files:
    if file.endswith(".d.ts")
        break
else:
    # TODO
    pass

Coming from Python, it was surprising to see this loop construct unsupported. AFAIK there is no reason (e.g. Turing completeness, semantics incompatibility) to not support for-else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions