Language Proposal: Enhancing for Loop with else Branch

In Verse, I love using the for loop for filtering, especially in cases like this:

FilterResult := for:
    Element:Elements
    ConditionFunction[]
do:
    Element

However, I often find myself wanting not only to save the filtered result but also to perform specific actions on elements that do not meet the filter condition. This need could be elegantly addressed by introducing an else branch within the for loop, allowing users to handle elements that are filtered out directly.

Here’s an example of what this might look like:

FilterResult := for:
    Element:Elements
    ConditionFunction[]
do:
    Element
else:
    DoSomethingWith(Element)

With this syntax, we can process the filtered results and simultaneously handle the unfiltered elements, making the code more readable and reducing the need for additional filtering steps.

@Uxibeo Thank you for your feedback. While I cannot guarantee a response, I can confirm that this has been forwarded to the appropriate team.