Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Loop Structures (Visual Basic)
In this articleVisual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is The following illustration shows a loop structure that runs a set of statements until a condition becomes true: While LoopsThe Do LoopsThe For LoopsThe For Each LoopsThe See also
FeedbackSubmit and view feedback for Skip to main content This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Statements (C# Programming Guide)
In this articleThe actions that a program takes are expressed in statements. Common actions include declaring variables, assigning values, calling methods, looping through collections, and branching to one or another block of code, depending on a given condition. The order in which statements are executed in a program is called the flow of control or flow of execution. The flow of control may vary every time that a program is run, depending on how the program reacts to input that it receives at run time. A statement can consist of a single line of code that ends in a semicolon, or a series of single-line statements in a block. A statement block is enclosed in {} brackets and can contain nested blocks. The following code shows two examples of single-line statements, and a multi-line statement block:
Types of statementsThe following table lists the various types of statements in C# and their associated keywords, with links to topics that include more information:
Declaration statementsThe following code shows examples of variable declarations with and without an initial assignment, and a constant declaration with the necessary initialization.
Expression statementsThe following code shows examples of expression statements, including assignment, object creation with assignment, and method invocation.
The empty statementThe following examples show two uses for an empty statement:
Embedded statementsSome statements, for example, iteration statements, always have an embedded statement that follows them. This embedded statement may be either a single statement or multiple statements enclosed by {} brackets in a statement block. Even single-line embedded statements can be enclosed in {} brackets, as shown in the following example:
An embedded statement that is not enclosed in {} brackets cannot be a declaration statement or a labeled statement. This is shown in the following example:
Put the embedded statement in a block to fix the error:
Nested statement blocksStatement blocks can be nested, as shown in the following code:
Unreachable statementsIf the compiler determines that the flow of control can never reach a particular statement under any circumstances, it will produce warning CS0162, as shown in the following example:
C# language specificationFor more information, see the Statements section of the C# language specification. See also
FeedbackSubmit and view feedback for What structure causes a statement or a set of statements to execute repeatedly?A repetition structure causes a statement or set of statements to execute repeatedly. Repetition structures are used to perform the same task over and over. A condition-controlled loop uses a Boolean (true/false) condition to control the number of times that it repeats.
What is the structure that causes a statement or a set of statements to execute repeatedly quizlet?More commonly known as a loop, a repetition structure causes a statement or set of statements to execute repeatedly as many times as necessary.
Which C++ structureLoops. A Loop is a control structure that causes a statement or group of statements to be executed repeatedly. Frequently in a program you will want to repeat an action several times or until some condition is met.
Which type of loop causes a statement or set of statements to repeat as long as a condition is true?Which pair of loops causes a statement or set of statements to repeat as long as a condition is true? The While loop is known as a pretest loop, which means it tests its condition before performing an iteration.
|