Logo

Programming-Idioms

History of Idiom 7 > diff from v111 to v112

Edit summary for version 112 by zqwnvl:
[VB] Move demo code to runnable demo; use names specified in lead

Version 111

2021-08-16, 21:11:54

Version 112

2021-08-24, 03:45:42

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Imports
Imports
Imports System
Code
Dim ItemList As New List(Of String)(New String() {"one", "two", "three"})
For x = 0 To ItemList.Count - 1
    Console.WriteLine(x & " " & ItemList(x))
Next
Code
For i As Integer = 0 To items.Count - 1
    Dim x = items(i)
    Console.WriteLine($"Item {i} = {x}")
Next
Comments bubble
items is IList(Of T)
Demo URL
https://sharplab.io/#gist:69474b9a495ea1757f41595c098ce0ee