-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
For ... Next Loop
Given the following section of code, it can be written as
For x = 0 To 9
For y = 0 To 9
Console.WriteLine($"{x} * {y} = {x*y}")
Next
Nextor
For x = 0 To 9
For y = 0 To 9
Console.WriteLine($"{x} * {y} = {x*y}")
Next x. yYet we can not write
For x = 0 To 9, y = 0 To 9
Console.WriteLine($"{x} * {y} = {x*y}")
Next x. y
or
For x = 0 To 9, y = 0 To 9
Console.WriteLine($"{x} * {y} = {x*y}")
Next ' equivalent to Next y : Next xWe should enable the last two scenario to compile.
Note: For what if the inner code contains exit continue `
For Each ... Next Loop
Premise
The premise of this feature is to allow the user to specify multiple iterators on a single For Each.
Basic Structrure
For Each x In xs, y In ys
' ...
' exit ' exits ys iterator
` exit x ' exits xs iterator
' continue ' goto next iteration of ys
' continue x ' goto next iteration of xs
' Next ' an error? / goto next iteration of ys then xs?
Next y , x
Example
Public Overrides ReadOnly Property AdditionalLocations As IReadOnlyList(Of Location)
Get
Dim builder = ArrayBuilder(Of Location).GetInstance()
For Each sym In AmbiguousSymbols, l In sym.Locations
builder.Add(l)
Next l, sym
Return builder.ToImmutableAndFree()
End Get
End Propertysemantically equivalent to the following
Public Overrides ReadOnly Property AdditionalLocations As IReadOnlyList(Of Location)
Get
Dim builder = ArrayBuilder(Of Location).GetInstance()
For Each sym In AmbiguousSymbols
For Each l In sym.Locations
builder.Add(l)
Next
Next
Return builder.ToImmutableAndFree()
End Get
End PropertyEdit For Each already supports this syntax.
zspitz and edin