dotnet / dotnet/vblang

Range `1 To 10 Step 2` expressions

Open
#25 9 comments 5 reactions 0 assignees View on GitHub
Discussion Proposal Prototype-Needed
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

[(Ported from Roslyn repo)](https://github.com/dotnet/roslyn/issues/13283)

**Range Query Syntax**

``` vb.net
Dim odd = From x In 1 To 100 Step 2
Dim HundredToZero = From x In 100 To 0 Step -2
```

**Updated (04 Dec 2017)**
The `range expression` will produce a range object, that has the capability of being enumerated.
```vbnet
Dim r As Range(of Byte, Sbyte) = Byte.MaxValue To Byte.MInValue Step -1
```
Compatibility rules of types, will be the same as those used for addition and subtract.
This to allow simple unsigned type to be used with signed types.
*We may want a code advisory, that can detect possible failures at compile-time. Eg unsigned beyond the limits of signed.*

The range used will be (inclusive, inclusive), so that expressing the full range of values is permitted eg.
```vbnet
Dim byteValues = From Byte.MinValue To Byte.MaxValue ' 256 values (not 255)`
```
Production of the values from the enumerator isnot allowed to overflow / underflow, regardless of any options eg `Option Checked Off` This is to allow an alternative form of **For Loop**
```vbnet
For Each value In Byte.MaxValue To Byte.MinValue Step -1
'...
Next
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.