Skip to content

Range/interval comprehension in 'for/while' loops #11381

Closed

Description

We could benefit from range/interval comprehension in 'for/while' loops:
for (i in 1..10) { someCodeHere(); }
could be optimized by the compiler using the classical for loop construct:
for (i=1; i<=10; i++) { someCodeHere(); }

or, with the 'while' construct:
while (i in min..max) { ... }
could be comprehended as
while (i >= min && i <= max) { ... }

*might also work for other iteration-based constructs and for array/tuple construction, but this is a different story.

Activity

  1. yortus commented on Oct 5, 2016

    @yortus
    Contributor

    ES Discuss is probably a better place to suggest this. TypeScript aims to be a superset of ECMAScript with static typing added. What you are proposing is new language syntax, rather than something related to static typing specifically.

    TypeScript would likely only consider this if it was already a fairly advanced proposal for ECMAScript. OTOH, if this gets picked up for a future version of ECMAScript, it will eventually make its way into TypeScript.

  2. ghost closed this as completedon Oct 5, 2016
  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions