概述
Public Class Form1
Private Sub btnForNextLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForNextLoop.Click
Dim intCount As Integer
ClearList()
For intCount = 1 To 5
lstData.Items.Add("I'm item " & intCount.ToString & "in the list.")
Next
End Sub
Private Sub ClearList()
lstData.Items.Clear()
End Sub
Private Sub btnForNextLoopWithStep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForNextLoopWithStep.Click
ClearList()
For intcount As Integer = 4 To 62 Step 7
lstData.Items.Add(intcount.ToString)
Next
End Sub
Private Sub btnBackwarksForNextLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackwarksForNextLoop.Click
ClearList()
For intCount As Integer = 10 To 1 Step -1
lstData.Items.Add(intCount.ToString)
Next
End Sub
Private Sub btnForEachLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForEachLoop.Click
ClearList()
For Each strFolder As String In My.Computer.FileSystem.GetDirectories("C:")
lstData.Items.Add(strFolder)
Next
End Sub
Private Sub btnDoUntilLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoUntilLoop.Click
Dim objRandom As New Random
Dim intRandomNumber As Integer = 0
ClearList()
'语句循环执行直到满足条件为止
Do Until intRandomNumber = 10
'生成一个0~24的随机整数
intRandomNumber = objRandom.Next(25)
lstData.Items.Add(intRandomNumber.ToString)
Loop
End Sub
Private Sub btnDoUntilLoop2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoUntilLoop2.Click
Dim objRandom As New Random
Dim intRandomNumber As Integer = 0
ClearList()
'语句循环执行直到满足条件为止
Do
'生成一个0~24的随机整数
intRandomNumber = objRandom.Next(25)
lstData.Items.Add(intRandomNumber.ToString)
Loop Until intRandomNumber = 10
End Sub
Private Sub btnDoWhileLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoWhileLoop.Click
Dim objRandom As New Random
Dim intRandomNumber As Integer = 0
ClearList()
Do While intRandomNumber < 15
intRandomNumber = objRandom.Next(25)
lstData.Items.Add(intRandomNumber.ToString)
Loop
End Sub
Private Sub btnDoWhileLoop2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoWhileLoop2.Click
Dim objRandom As New Random
Dim intRandomNumber As Integer = 0
ClearList()
Do
intRandomNumber = objRandom.Next(25)
lstData.Items.Add(intRandomNumber.ToString)
Loop While intRandomNumber < 15
End Sub
Private Sub btnNestedLoops_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNestedLoops.Click
ClearList()
For intOuterLoop As Integer = 1 To 2
For intInnerLoop As Integer = 1 To 3
lstData.Items.Add(intOuterLoop.ToString & "," & intInnerLoop.ToString)
Next
Next
End Sub
Private Sub btnQuittingAForLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuittingAForLoop.Click
ClearList()
For Each strFolder As String In My.Computer.FileSystem.GetDirectories("C:")
lstData.Items.Add(strFolder)
'检查是否存在C:program files文件夹
If String.Compare(strFolder, "C:program files", True) = 0 Then
MessageBox.Show("Fount it ,exiting the loop now.", "Loops")
Exit For
End If
Next
End Sub
Private Sub btnQuittingADoLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuittingADoLoop.Click
Dim intCount As Integer = 0
ClearList()
Do While intCount < 10
lstData.Items.Add(intCount.ToString)
intCount += 1
If intCount = 3 Then
Exit Do
End If
Loop
End Sub
End Class
最后
以上就是大力小鸭子为你收集整理的VB2010(11)_循环语句的全部内容,希望文章能够帮你解决VB2010(11)_循环语句所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复