Vbs basics-loop Statement (4)-For each... Next

Source: Internet
Author: User

For each... the next loop is similar to the for... next loop. For each... next does not mean to run the specified number of times, but repeats a group of statements for each element or object set in the array. This is useful when you do not know the number of elements in the collection.

The syntax structure is as follows:  

12345 For Each element In group    [statements]    [Exit For]    [statements]Next [element]

Main parameters:

Element: Used to enumerate variables of all elements in a set or array. For a set, element may be a variant variable, a common object variable, or any specified automation object variable. For arrays, element can only be a variant variable.

Group: Name of the object set or array.

The specific instance code is as follows:

12345678 Dim Dics 'Defines a variableSet Dics = CreateObject("Scripting.Dictionary") 'Define a dictionary objectDics.Add "0", "Athens"'Assigns a value to the dictionary objectDics.Add "1", "Belgrade"Dics.Add "2", "Cairo"For Each Dic in Dics    MsgBox Dics.Item(Dic) 'Looping and outputting the dictionary key valueNext

 

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.