Exit語(yǔ)句將控制從過(guò)程或塊立即傳遞到過(guò)程調(diào)用或塊定義之后的語(yǔ)句。 它終止循環(huán),過(guò)程,try塊或從其被調(diào)用的選擇塊。
如果你使用嵌套循環(huán)(即在另一個(gè)循環(huán)中有一個(gè)循環(huán)),Exit語(yǔ)句將停止最內(nèi)層循環(huán)的執(zhí)行,并開(kāi)始執(zhí)行塊后的下一行代碼。
Exit語(yǔ)句的語(yǔ)法是:
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當(dāng)上述代碼被編譯和執(zhí)行時(shí),它產(chǎn)生以下結(jié)果:
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15
更多建議: