' Visual Basic 2008 9.0 .NET Examples - Searching through Arrays - Binary Search - Arrays : Module ExerciseSolution Sub Main() Dim count As Integer = 3 Dim names() As String = {"Brussels", "Antwerp", "Ghent"} Dim zipCodes() As Integer = {1000, 2000, 9000} ' Console.WriteLine("Zip Code ?") Dim zipCode As String = Console.ReadLine() ' Dim found, exhausted As Boolean Dim lowerbound, index As Integer Dim upperbound As Integer = count - 1 Do Until found OrElse exhausted index = (lowerbound + upperbound) \ 2 found = (zipCode = zipCodes(index)) exhausted = (upperbound <= lowerbound) If Not (found OrElse exhausted) Then If zipCode > zipCodes(index) Then lowerbound = index + 1 Else upperbound = index - 1 End If End If Loop ' If found Then Console.WriteLine(names(index)) Else Console.WriteLine("City not found.") End If ' Console.ReadLine() End Sub End Module ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.