I'm currently reading Code Complete by Steve McConnell. In section 12.6, Enumerated Types, he says that we can define first and last entries like limits:
Define the first and last entries of an enumeration for use as loop limits Defining the first and last elements in an enumeration to be Color_First, Color_Last, Country_First, Country_Last, and so on allows you to write a loop that loops through the elements of an enumeration. You set up the enumerated type by using explicit values, as shown here:
Visual Basic Example of Setting First and Last Values in an Enumerated Type
Public Enum Country Country_First = 0 Country_China = 0 Country_England = 1 Country_France = 2 Country_Germany = 3 Country_India = 4 Country_Japan = 5 Country_Usa = 6 Country_Last = 6 End Enum
Now the Country_First and Country_Last values can be used as loop limits:
Good Visual Basic Example of Looping Through Elements in an Enumeration
' compute currency conversions from US currency to target currency Dim usaCurrencyConversionRate( Country_Last ) As Single Dim iCountry As Country For iCountry = Country_First To Country_Last usaCurrencyConversionRate( iCountry ) = ConversionRate( Country_Usa, iCountry ) Next
Why do we need duplicated indices on the edges for enumerated type?
For iCountry = Country_First To Country_Last
.