Vbs Tutorial: VBScript statement-for each... Next statement

Source: Internet
Author: User

For each... next statement

Execute a set of statements repeatedly for each element in an array or set.

For eachElement in group
[Statements]
[Exit for]
[Statements]
Next[Element]

Parameters

Element

Used to enumerate variables of all elements in a set or array. For a set,ElementIt may beVariantVariable, GeneralObjectVariable or any specified automation object variable. For arrays,ElementOnly yesVariantVariable.

Group

The name of the object set or array.

Statements

ForGroupOne or more statements executed by each item in.

Description

IfGroupIf there is at least one element, it will enterFor eachBlock execution. Once the cycle is enteredGroupThe first element in the execution cycle. As longGroupWhen there are other elements, the statement in the loop is executed for each element. WhenGroupWhen there are no other elements inNextStatement.

ExitCan only be usedFor each... NextOrFor... NextIn the control structure, an exit loop method is provided. You can place any number of entries at any point in the loop.ExitStatement.ExitIt is often used with condition-based judgment statements (for exampleIf... then), And immediately transfer controlNext.

You canFor each... NextLoops are placed in the other to form a nestedFor each... NextLoop. HoweverElementIt must be unique.

Note:If omittedNextStatementElement, ThenProgramThe execution will continue as it already exists. IfNextStatement in the correspondingForIf the statement appears before the statement, an error occurs.

The following example illustrates how to useFor each... NextStatement:

 
Function showfolderlist (folderspec) dim FSO, F, F1, FC, s set FSO = Createobject ("scripting. fileSystemObject ") set f = FSO. getfolder (folderspec) set fc = f. filesFor eachF1InFc s = S & f1.name S = S & "<br>" next showfolderlist = Send Function

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.