﻿'Visual Basic 2012 Herhalingen met For ... Next Basisstructuren van Algoritmes Module ForNextExample1 Sub Main() Dim value As Integer ' For value = 1 To 10 Console.WriteLine(value) Next ' Console.ReadLine() End Sub End Module Module ForNextWithStartValueOtherThan1Example Sub Main() Dim value As Integer ' For value = 10 To 15 Console.WriteLine(value) Next ' Console.ReadLine() End Sub End Module Module ForNextWithStepValueExample Sub Main() Dim value As Integer ' For value = 2 To 10 Step 2 Console.WriteLine(value) Next ' Console.ReadLine() End Sub End Module Module ForNextWithNegativeStepValueExample Sub Main() Dim value As Integer ' For value = 10 To 0 Step -2 Console.WriteLine(value) Next ' Console.ReadLine() End Sub End Module Module ForNextExample2 Sub Main() Dim countValue As Integer Dim startValue As Integer = 1 Dim endValue As Integer = 10 Dim stepValue As Integer = 2 ' Console.WriteLine("values during iteration :") For countValue = startValue To endValue Step stepValue Console.WriteLine("count value : " & countValue) ' countValue = countValue + 1 startValue = startValue + 1 endValue = endValue + 1 stepValue = stepValue + 1 Next ' Console.WriteLine("values after iteration :") Console.WriteLine("count value : " & countValue) Console.WriteLine("start value : " & startValue) Console.WriteLine("end value : " & endValue) Console.WriteLine("step value : " & stepValue) ' Console.ReadLine() End Sub End Module Module ForNextExercise1 Sub Main() Console.WriteLine("Value ?") Dim value As Integer = Console.ReadLine() ' Dim factorial As Integer = value Dim factor As Integer = value - 1 ' For factor = value - 1 To 2 Step -1 factorial = factorial * factor Next ' Console.WriteLine(value & "! = " & factorial) ' Console.ReadLine() End Sub End Module Module ForNextExercise2 Sub Main() Dim hours, minutes, seconds As Integer Dim timeLabel As String For hours = 0 To 23 For minutes = 0 To 59 For seconds = 0 To 59 timeLabel = "" If hours < 10 Then timeLabel = "0" End If timeLabel = timeLabel & hours & "h" If minutes < 10 Then timeLabel = timeLabel & "0" End If timeLabel = timeLabel & minutes & "m" If seconds < 10 Then timeLabel = timeLabel & "0" End If timeLabel = timeLabel & seconds & "s" Console.WriteLine(timeLabel) Next Next Next Console.ReadLine() End Sub End Module 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2012 - Alle rechten voorbehouden.