VBA Loop statement

Source: Internet
Author: User
Tags exit numeric

statements, in addition to judging statements, there are circular statements, there are several forms:

1, while ... Wend statement. Grammar:

While condition

[Statements]

Wend

While ... The syntax for a Wend statement has the following sections:

Partial description

Condition necessary parameters. A numeric expression or string expression that evaluates to TRUE or False. If condition is Null, condition is treated as False.

Statements Optional parameters. One or more statements that are executed when the condition is true.

2, do ... The Loop statement. Grammar:

Do [{while | Until} condition]

[Statements]

[Exit do]

[Statements]

Loop

Or you can use the following syntax:

Todo

[Statements]

[Exit do]

[Statements]

Loop [{while | Until} condition]

The parameter descriptions in the syntax of DO Loop statements are the same as above and do not repeat.

3, for ... Next statement. Grammar:

For counter = start to end [step step]

[Statements]

[Exit for]

[Statements]

Next [counter]

For ..... The syntax for the NEXT statement has the following sections:

Partial description

Counter necessary parameters. A numeric variable used as a loop counter. This variable cannot be a Boolean or an array element.

The necessary parameters for start. The initial value of the counter.

End necessary parameter, counter final value.

Step optional parameter. The step size of the counter. If not specified, the default value for step is 1.

Statements Optional parameters. One or more statements that are placed between for and Next, and they are executed the specified number of times.

4. For Each ... Next statement. Grammar

For each element in group

[Statements]

[Exit for]

[Statements]

Next [element]

For ..... Each ... The syntax for the NEXT statement has the following sections:

Partial description

Element necessary parameters. A variable used to traverse a collection or all elements in an array. For a collection, the element may be a Variant variable, a generic object variable, or any special object variable. For an array, an element can only be a variant variable.

Group necessary parameters. The name of the object collection or array, except for an array of user-defined types.

Statements an optional parameter that executes one or more statements for each item in the group.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.