Simplified for loop #7535
Unanswered
wojciechsura
asked this question in
Language Ideas
Replies: 1 comment
-
Covered in #2810. The use case is concrete, we can discuss for the syntax later. Moreover, if the iteration count is constant, the compiler (roslyn or JIT) can choose to unroll it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm proposing a simplified for loop in cases that something needs to be done x times, but we don't care about the iterator.
Let's consider the following scenario:
The simplified notation would allow the following:
Rationale:
For loop is used if we care about the index of processed item. Foreach loop is used if we care about the processed item. However, there is no option if we only care about certain number of executions.
This is a syntax simplification on the same level as e.g. simplifying using statements so that they don't require braces if their scope equals to enclosing scope.
Alternative:
Not too many. The only one that comes to my mind is:
However, this one is even longer than a regular for loop.
Beta Was this translation helpful? Give feedback.
All reactions