📜  VB.Net-循环

📅  最后修改于: 2020-11-19 08:49:28             🧑  作者: Mango


在某些情况下,您需要多次执行一个代码块。通常,语句是按顺序执行的:函数的第一个语句首先执行,然后第二个执行,依此类推。

编程语言提供了各种控制结构,允许更复杂的执行路径。

循环语句使我们可以多次执行一个语句或一组语句,以下是大多数编程语言中循环语句的一般形式-

循环架构

VB.Net提供以下类型的循环来处理循环需求。单击以下链接以查看其详细信息。

Loop Type Description

Do Loop

It repeats the enclosed block of statements while a Boolean condition is True or until the condition becomes True. It could be terminated at any time with the Exit Do statement.

For…Next

It repeats a group of statements a specified number of times and a loop index counts the number of loop iterations as the loop executes.

For Each…Next

It repeats a group of statements for each element in a collection. This loop is used for accessing and manipulating all elements in an array or a VB.Net collection.

While… End While

It executes a series of statements as long as a given condition is True.

With… End With

It is not exactly a looping construct. It executes a series of statements that repeatedly refer to a single object or structure.

Nested loops

You can use one or more loops inside any another While, For or Do loop.

循环控制语句

循环控制语句从其正常顺序更改执行。当执行离开作用域时,在该作用域中创建的所有自动对象都将被销毁。

VB.Net提供以下控制语句。单击以下链接以查看其详细信息。

Control Statement Description

Exit statement

Terminates the loop or select case statement and transfers execution to the statement immediately following the loop or select case.

Continue statement

Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

GoTo statement

Transfers control to the labeled statement. Though it is not advised to use GoTo statement in your program.