是否可以在VB.NET中编写无限循环?
如果是这样,语法是什么?
答案 0 :(得分:15)
Do
Something
Loop
答案 1 :(得分:8)
For i as Integer = 0 To 1 Step 0
如果那不够hacky,也可以写:
For i As Integer = 0 To 2
i -= 1
Next
答案 2 :(得分:5)
或
while (true)
end while
好的,正确的答案:
Dim InfiniteLoop as Boolean = true;
For i = 1 to 45687894
If i = 45687893 And InfiniteLoop = true Then i = 1
End For
答案 3 :(得分:2)
除了为循环运行所给出的所有答案之外,这可能只是第一个实际使用正无穷大的值来限制循环。但为了安全起见,我在一段给定的秒数后包含了一个额外的选项,以便它可以测量循环的速度。
Sub RunInfinateForLoop(maxSeconds As Integer)
' Attempts to run a For loop to infinity but also exits if maxSeconds seconds have elapsed.
Dim t As Date = Now
Dim exitTime As Date = t.AddSeconds(maxSeconds)
Dim dCounter As Double
Dim strMessage As String
For dCounter = 1 To Double.PositiveInfinity
If Now >= exitTime Then Exit For
Next
strMessage = "Loop ended after " & dCounter.ToString & " loops in " & maxSeconds & " seconds." & vbCrLf &
"Average speed is " & CStr(dCounter / maxSeconds) & " loops per second."
MsgBox(strMessage, MsgBoxStyle.OkOnly, "Infinity Timer")
End Sub
答案 4 :(得分:0)
我做的是添加一个计时器,然后我将间隔更改为1,然后我启用它然后如果我希望它通过循环不断检查一下我只需双击timer_tick事件的计时器然后我输入我的内容想。如果我希望它能保存所有内容,我通常会使用它来更新设置。