Share do while vb.net

** làm trong khi vòng lặp trong vb.net **

A ** làm trong khi 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ã miễn là một điều kiện được chỉ định là đúng.Cú pháp của một vòng trong khi vòng như sau:

`` `VBNet
Làm trong khi điều kiện
// khối mã sẽ được thực thi
Vòng
`` `

Điều kiện được đánh giá ở đầu mỗi lần lặp của vòng lặp.Nếu điều kiện là đúng, khối mã được thực thi.Nếu điều kiện là sai, vòng lặp chấm dứt.

Ví dụ: mã sau in các số từ 1 đến 10:

`` `VBNet
Dim I As Integer
i = 1
Làm trong khi tôi <= 10
Console.WriteLine (i)
i = i + 1
Vòng
`` `

** Thoát khỏi việc làm trong khi vòng lặp **

Bạn có thể thoát ra khỏi một vòng trong khi sử dụng câu lệnh ** EXIT do **.Tuyên bố ** thoát ** ngay lập tức chấm dứt vòng lặp, bất kể giá trị của điều kiện.

Ví dụ: mã sau in các số từ 1 đến 10, nhưng nó bị hỏng khỏi vòng lặp khi đạt được số 5:

`` `VBNet
Dim I As Integer
i = 1
Làm trong khi tôi <= 10
Nếu tôi = 5 thì
Thoát khỏi làm
Kết thúc nếu
Console.WriteLine (i)
i = i + 1
Vòng
`` `

** Sử dụng từ khóa cho đến khi **

Việc làm trong khi vòng lặp cũng có thể được sử dụng với từ khóa ** cho đến **.Từ khóa ** cho đến ** Chỉ định rằng vòng lặp sẽ tiếp tục miễn là điều kiện được chỉ định là sai.Cú pháp của A DO cho đến khi vòng lặp như sau:

`` `VBNet
Làm cho đến khi điều kiện
// khối mã sẽ được thực thi
Vòng
`` `

Mã sau in các số từ 1 đến 10, nhưng nó bắt đầu với số 10 và đếm ngược:

`` `VBNet
Dim I As Integer
i = 10
Làm cho đến khi tôi <= 0
Console.WriteLine (i)
i = i - 1
Vòng
`` `

** hashtags **

* #DowHileloop
* #vb.net
* #Programming
* #Loops
* #Conditionals
=======================================
**Do While Loop in VB.NET**

A **Do While loop** in VB.NET is a programming construct that repeats a block of code as long as a specified condition is true. The syntax of a Do While loop is as follows:

```vbnet
Do While condition
// code block to be executed
Loop
```

The condition is evaluated at the beginning of each iteration of the loop. If the condition is true, the code block is executed. If the condition is false, the loop terminates.

For example, the following code prints the numbers from 1 to 10:

```vbnet
Dim i As Integer
i = 1
Do While i <= 10
Console.WriteLine(i)
i = i + 1
Loop
```

**Breaking out of a Do While loop**

You can break out of a Do While loop using the **Exit Do** statement. The **Exit Do** statement immediately terminates the loop, regardless of the value of the condition.

For example, the following code prints the numbers from 1 to 10, but it breaks out of the loop when the number 5 is reached:

```vbnet
Dim i As Integer
i = 1
Do While i <= 10
If i = 5 Then
Exit Do
End If
Console.WriteLine(i)
i = i + 1
Loop
```

**Using the Until keyword**

The Do While loop can also be used with the **Until** keyword. The **Until** keyword specifies that the loop should continue as long as the specified condition is false. The syntax of a Do Until loop is as follows:

```vbnet
Do Until condition
// code block to be executed
Loop
```

The following code prints the numbers from 1 to 10, but it starts with the number 10 and counts down:

```vbnet
Dim i As Integer
i = 10
Do Until i <= 0
Console.WriteLine(i)
i = i - 1
Loop
```

**Hashtags**

* #DowHileloop
* #vb.net
* #Programming
* #Loops
* #Conditionals
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top