Share vb.net exit for loop

sonhaiphamthuc

New member
### Cách thoát một vòng lặp trong VB.NET

**Tổng quan**

Một vòng lặp trong vb.net là một cấu trúc lập trình lặp lại một khối mã một số lần được chỉ định.Vòng lặp lặp lại trong một loạt các giá trị và mỗi lần nó thực hiện, mã trong khối được thực thi.Để thoát một vòng lặp sớm, bạn có thể sử dụng câu lệnh `exit for`.

** Cú pháp **

Cú pháp cho câu lệnh `thoát for` như sau:

`` `
Thoát khỏi cho
`` `

Bạn có thể sử dụng câu lệnh `EXIT for` ở bất cứ đâu trong phần thân của vòng lặp.Khi câu lệnh được thực thi, vòng lặp sẽ ngay lập tức chấm dứt và chương trình sẽ tiếp tục với câu lệnh tiếp theo sau vòng lặp.

**Ví dụ**

Ví dụ sau đây cho thấy cách sử dụng câu lệnh `exit for` để thoát một vòng lặp sớm:

`` `
Dim I As Integer

Cho i = 1 đến 10
Nếu tôi = 5 thì
Thoát khỏi cho
Kết thúc nếu

'Làm gì đó ở đây
Tiếp theo tôi
`` `

Trong ví dụ này, vòng lặp lặp lại từ 1 đến 10. Tuy nhiên, nếu giá trị của `i` bằng 5, câu lệnh` exit for` sẽ được thực thi và vòng lặp sẽ chấm dứt sớm.

** Tài nguyên bổ sung **

* [Vb.net cho hướng dẫn vòng lặp] (https://www.w3schools.com/vbnet/vbnet_for_loop.asp)
* [VB.NET Thoát cho tuyên bố] (https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.enumere.exitfor)

### hashtags

* #vb.net
* #cho vòng lặp
* #exit cho
* #Programming
* #tutorial
=======================================
### How to Exit a For Loop in VB.NET

**Overview**

A for loop in VB.NET is a programming construct that repeats a block of code a specified number of times. The loop iterates over a range of values, and each time it does, the code in the block is executed. To exit a for loop early, you can use the `Exit For` statement.

**Syntax**

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

```
Exit For
```

You can use the `Exit For` statement anywhere within the body of the for loop. When the statement is executed, the loop will immediately terminate and the program will continue with the next statement after the loop.

**Example**

The following example shows how to use the `Exit For` statement to exit a for loop early:

```
Dim i As Integer

For i = 1 To 10
If i = 5 Then
Exit For
End If

' Do something here
Next i
```

In this example, the loop iterates from 1 to 10. However, if the value of `i` is equal to 5, the `Exit For` statement will be executed and the loop will terminate early.

**Additional Resources**

* [VB.NET For Loop Tutorial](https://www.w3schools.com/vbnet/vbnet_for_loop.asp)
* [VB.NET Exit For Statement](https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.enumerable.exitfor)

### Hashtags

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