Share exit for loop vb.net

nhatminhbarker

New member
Har

Câu lệnh `EXIT for` trong vb.net được sử dụng để chấm dứt vòng lặp` for` sớm.Nó có thể được sử dụng khi bạn không còn cần lặp lại thông qua bộ sưu tập các mục của vòng lặp.

Cú pháp của câu lệnh `EXIT FOR` như sau:

`` `vb.net
Thoát khỏi cho
`` `

Bạn cũng có thể sử dụng câu lệnh `exit for` với biểu thức.Biểu thức này sẽ được đánh giá và nếu nó đánh giá là `true`, vòng` for` sẽ bị chấm dứt.Cú pháp của câu lệnh `EXIT FOR` với biểu thức như sau:

`` `vb.net
Thoát khỏi biểu thức nếu biểu thức
`` `

Ví dụ: mã sau sử dụng câu lệnh `exit for` để chấm dứt vòng lặp` for` khi biến `i` bằng 5:

`` `vb.net
Cho i = 1 đến 10
Nếu tôi = 5 thì
Thoát khỏi cho
Kết thúc nếu
Console.WriteLine (i)
Kế tiếp
`` `

Câu lệnh `EXIT FOR` có thể được sử dụng để cải thiện hiệu suất của mã của bạn bằng cách chấm dứt một vòng lặp sớm khi nó không còn cần thiết.Tuy nhiên, bạn nên sử dụng câu lệnh `Exit for` một cách thận trọng, vì nó có thể làm cho mã của bạn khó đọc và gỡ lỗi hơn.

###### Bài viết tham khảo

* [Vb.net cho vòng lặp] (https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-loop)
* [VB.NET Thoát cho câu lệnh] (https://docs.microsoft.com/en-us/do...guage-reference/statements/exit-for-statement)

###### Hashtags

* #vb.net
* #vòng
* #lối ra
* #phá vỡ
* #Programming
=======================================
#vb.net #loop #exit #Break #Programming ##Exit for loop in VB.NET

The `Exit For` statement in VB.NET is used to terminate a `For` loop early. It can be used when you no longer need to iterate through the loop's collection of items.

The syntax of the `Exit For` statement is as follows:

```vb.net
Exit For
```

You can also use the `Exit For` statement with an expression. This expression will be evaluated, and if it evaluates to `True`, the `For` loop will be terminated. The syntax of the `Exit For` statement with an expression is as follows:

```vb.net
Exit For If expression
```

For example, the following code uses the `Exit For` statement to terminate a `For` loop when the `i` variable is equal to 5:

```vb.net
For i = 1 To 10
If i = 5 Then
Exit For
End If
Console.WriteLine(i)
Next
```

The `Exit For` statement can be used to improve the performance of your code by terminating a loop early when it is no longer needed. However, you should use the `Exit For` statement with caution, as it can make your code more difficult to read and debug.

###### Reference articles

* [VB.NET For Loop](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-loop)
* [VB.NET Exit For Statement](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/exit-for-statement)

###### Hashtags

* #vb.net
* #loop
* #exit
* #Break
* #Programming
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top