VB.NET 中的 do while 和 while 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16058154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Whats the difference between do while and while in VB.NET?
提问by jaffa
What's the difference between Do Whilewhere the statement is the first line in the loop block and just the single Whilein VB.NET?
语句是循环块中的第一行的Do While与VB.NET 中的单个While之间有什么区别?
They don't seem to offer any difference in behavior.
它们似乎在行为上没有任何区别。
回答by dbasnett
In Visual Basicthese are identical:
在 Visual Basic 中,这些是相同的:
Dim foo As Boolean = True
While Not foo
Debug.WriteLine("!")
End While
Do While Not foo
Debug.WriteLine("*")
Loop
These are not; the doexecutes once:
这些不是;在do执行一次:
Dim foo As Boolean = True
While Not foo
Debug.WriteLine("!")
End While
Do
Debug.WriteLine("*")
Loop While Not foo
回答by zeronillzero
In DO...WHILE, the code inside the loop is executed at least once
在DO...WHILE 中,循环内的代码至少执行一次
In WHILELoop, the code inside the loop is executed 0 or more times.
在WHILE循环中,循环内的代码被执行0 次或多次。
回答by Borniet
Do Whileexecutes first and then checks if valid. Whilechecks first and then executes.
Do While首先执行,然后检查是否有效。While先检查然后执行。
while (1!=1){ echo 1}
will output nothing
什么都不输出
But
但
do{echo 1} while (1!=1)
will output 1 once.
将输出 1 一次。

