目录

Exit statement

Exit语句将控制从过程或块立即传递到过程调用或块定义之后的语句。 它终止循环,过程,try块或调用它的select块。

如果您正在使用嵌套循环(即,另一个循环中的一个循环),则Exit语句将停止执行最内层循环并在块之后开始执行下一行代码。

语法 (Syntax)

Exit语句的语法是 -

Exit { Do | For | Function | Property | Select | Sub | Try | While }

流程图 (Flow Diagram)

VB.Net退出语句

例子 (Example)

Module loops
   Sub Main()
      ' local variable definition 
      Dim a As Integer = 10
      ' while loop execution '
      While (a < 20)
         Console.WriteLine("value of a: {0}", a)
         a = a + 1
         If (a > 15) Then
            'terminate the loop using exit statement 
            Exit While
         End If
      End While
      Console.ReadLine()
   End Sub
End Module

编译并执行上述代码时,会产生以下结果 -

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
↑回到顶部↑
WIKI教程 @2018