Vb.net-loops

提供:Dev Guides
移動先:案内検索

VB.Net-ループ

コードのブロックを数回実行する必要がある場合があります。 一般に、ステートメントは順番に実行されます。関数の最初のステートメントが最初に実行され、次に2番目のステートメントが実行されます。

プログラミング言語は、より複雑な実行パスを可能にするさまざまな制御構造を提供します。

ループステートメントを使用すると、ステートメントまたはステートメントのグループを複数回実行できます。ほとんどのプログラミング言語では、ループステートメントの一般的な形式は次のとおりです-

ループアーキテクチャ

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.