Exit
语句将过程或块中的控制立即转移到过程调用或块定义之后的语句中。它终止循环,过程,尝试块或从调用的选择块。
如果使用嵌套循环(即在一个循环内部有另外一个循环),则Exit
语句将停止最内层循环的执行,并开始执行块之后的下一行代码。
语法
Exit
语句的语法是:
Exit { Do | For | Function | Property | Select | Sub | Try | While }
流程图
示例
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