Share looping statement in vb.net,

giahungredbaron

New member
#vb.net #Looping #Programming #tutorial #development ## Câu lệnh LOOPING trong VB.NET

Các câu lệnh Vòng lặp được sử dụng để thực thi một khối mã nhiều lần.Các câu lệnh lặp phổ biến nhất trong vb.net là `for`,` while` và `làm trong khi`.

### cho vòng lặp

Vòng lặp `for` lặp qua một chuỗi các giá trị.Cú pháp của vòng `for` như sau:

`` `VBNet
Đối với <biến> = <start> to <end>
<Code>
Tiếp theo <Biến>
`` `

`<Biến>` là biến sẽ lưu trữ các giá trị trong chuỗi.`<Trom start>` là giá trị bắt đầu của chuỗi và `<Nom>` là giá trị kết thúc của chuỗi.`<code>` là khối mã sẽ được thực thi cho mỗi giá trị trong chuỗi.

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

`` `VBNet
Cho i = 1 đến 10
Console.WriteLine (i)
Tiếp theo tôi
`` `

### Trong khi lặp lại

Vòng lặp `while thực hiện một khối mã miễn là điều kiện là đúng.Cú pháp của vòng `while` như sau:

`` `VBNet
Trong khi <điều kiện>
<Code>
Kết thúc trong khi
`` `

`<Điều kiện>` là điều kiện phải đúng để vòng lặp tiếp tục.`<code>` là khối mã sẽ được thực thi trong khi điều kiện là đúng.

Ví dụ: mã sau in các số từ 1 đến 10, nhưng nó bỏ qua số 5:

`` `VBNet
i = 1
Trong khi tôi <11
Nếu tôi = 5 thì
i = i + 1
Tiếp tục
Kết thúc nếu
Console.WriteLine (i)
i = i + 1
Kết thúc trong khi
`` `

### làm trong khi vòng lặp

Vòng `DO while giống nhau tương tự như vòng lặp` while, nhưng khối mã được thực thi ít nhất một lần, ngay cả khi điều kiện là sai.Cú pháp của vòng lặp `do` như sau:

`` `VBNet
Làm trong khi <điều kiện>
<Code>
Vòng
`` `

`<Điều kiện>` là điều kiện phải đúng để vòng lặp tiếp tục.`<code>` là khối mã sẽ được thực thi trong khi điều kiện là đúng.

Ví dụ: mã sau in các số từ 1 đến 10, nhưng nó bỏ qua số 5:

`` `VBNet
i = 1
Làm trong khi tôi <11
Nếu tôi = 5 thì
i = i + 1
Tiếp tục
Kết thúc nếu
Console.WriteLine (i)
i = i + 1
Vòng
`` `

## Phần kết luận

Các câu lệnh lặp là một công cụ mạnh mẽ cho các lập trình viên.Chúng có thể được sử dụng để lặp lại thông qua một chuỗi các giá trị, thực thi một khối mã miễn là một điều kiện là đúng hoặc thực thi một khối mã ít nhất một lần.Bằng cách hiểu cách sử dụng các câu lệnh lặp, bạn có thể viết mã hiệu quả và hiệu quả hơn.

## hashtags

* #vb.net
* #Looping
* #Programming
* #tutorial
* #phát triển
=======================================
#vb.net #Looping #Programming #tutorial #development ## Looping Statements in VB.NET

Looping statements are used to execute a block of code multiple times. The most common looping statements in VB.NET are `For`, `While`, and `Do While`.

### For Loop

The `For` loop iterates through a sequence of values. The syntax of a `For` loop is as follows:

```vbnet
For <variable> = <start> To <end>
<code>
Next <variable>
```

The `<variable>` is the variable that will store the values in the sequence. The `<start>` is the starting value of the sequence, and the `<end>` is the ending value of the sequence. The `<code>` is the block of code that will be executed for each value in the sequence.

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

```vbnet
For i = 1 To 10
Console.WriteLine(i)
Next i
```

### While Loop

The `While` loop executes a block of code as long as a condition is true. The syntax of a `While` loop is as follows:

```vbnet
While <condition>
<code>
End While
```

The `<condition>` is the condition that must be true for the loop to continue. The `<code>` is the block of code that will be executed while the condition is true.

For example, the following code prints the numbers from 1 to 10, but it skips the number 5:

```vbnet
i = 1
While i < 11
If i = 5 Then
i = i + 1
Continue
End If
Console.WriteLine(i)
i = i + 1
End While
```

### Do While Loop

The `Do While` loop is similar to the `While` loop, but the block of code is executed at least once, even if the condition is false. The syntax of a `Do While` loop is as follows:

```vbnet
Do While <condition>
<code>
Loop
```

The `<condition>` is the condition that must be true for the loop to continue. The `<code>` is the block of code that will be executed while the condition is true.

For example, the following code prints the numbers from 1 to 10, but it skips the number 5:

```vbnet
i = 1
Do While i < 11
If i = 5 Then
i = i + 1
Continue
End If
Console.WriteLine(i)
i = i + 1
Loop
```

## Conclusion

Looping statements are a powerful tool for programmers. They can be used to iterate through a sequence of values, execute a block of code as long as a condition is true, or execute a block of code at least once. By understanding how to use looping statements, you can write more efficient and effective code.

## Hashtags

* #vb.net
* #Looping
* #Programming
* #tutorial
* #development
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top