verhaba
Gebruiker
- Lid geworden
- 8 feb 2008
- Berichten
- 79
Code:
Module Module1
Sub Main()
Dim base As Integer = 2
Dim count As Integer = 10
Dim upperbound As Integer = count - 1
Dim numbers(upperbound) As Integer
'
Dim index As Integer
For index = 0 To upperbound
' de waarden opvullen in de array.
' val index 0 = 1 * 2 (2)
' 1 = 2 * 2 (4)
' 2 = 3 * 2 (6)
' 3 = 4 * 2 (8)
numbers(index) = (index + 1) * base
Next
'
Dim number As Integer
' = 1 to 2 * 11 (22)
For number = base - 1 To base * count + 1
' linear search
Dim found As Boolean = False
Dim exhausted As Boolean = False
index = -1
Do Until found OrElse exhausted
index += 1
found = (numbers(index) = number)
exhausted = (index = upperbound)
Loop
' output
If found Then
Console.Write(number & " found at index " & index)
Else
Console.Write(number & " not found")
End If
If exhausted Then
Console.WriteLine(", search exhausted")
Else
Console.WriteLine(", search not exhausted")
End If
Next
'
Console.ReadLine()
End Sub
End Module