Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Check = 1
Dim NumberofLoops = 3
TextBox1.Text = 1
For Check = 1 To NumberofLoops
' some equations
If TextBox1.Text > 100 Then NumberofLoops = 100
MessageBox.Show("Check = " & Check)
Next
Label1.Text = Check
End Sub
End Class
答案 0 :(得分:4)
如果你真的需要在循环内部更改循环参数,那么FOR / NEXT将不起作用。您需要使用DO/LOOP替代方案。 E.g。
Dim NumberofLoops = 3
Dim Check = 1
Do While Check <= NumberofLoops
If TextBox1.Text > 100 Then NumberofLoops = 100
Check += 1
Loop