Reputation: 2597
I would like to loop through two lists using a For each loop.
dim data as list(of pointpairlist)
For each recLine in records
For Each chan In recLine.channels and d in data
d.add( func(chan) )
Next
next
note: each record line has one sample from each channel recorded. ie each record line is a slice of a 32 sensor recordings. I want to build up a x,y list of data points for each channel (the x axis is common to all channels)
Is there some way to do it similar to what i have above (avoiding indexing variables)
Upvotes: 1
Views: 5097
Reputation: 941317
Nest the loops. I cannot reverse-engineer the actual declarations from the snippet, but something like this:
Dim data As List(Of PointPairList)
''...
For Each point In data
For Each chan In point.recLine
func(chan)
Next
Next
Upvotes: 2
Reputation: 498942
The best way to iterate over two different collections in a single loop is to use indexers.
For index As Integer = 0 To recLine.channels.Count - 1
data(index) = func(chan(index))
Next
As @0xA3 comments, you can also a while loop, calling GetEnumerator
, MoveNext
and Current
directly on each collection, but this buys you nothing.
I realize you want to avoid using indexers, but there is no simple language support for anything else.
This is the case also for C#.
Why do you need to avoid indexers?
Upvotes: 2