The <12> enumeration and iterative __aauto of Aauto Learning Series

Source: Internet
Author: User

Both enumerations and iterations provide the ability to traverse the elements of a collection object.

I. Enumeration
Refers to calling an enumeration function, enumerating the elements of the collection at a single point, usually by specifying a trigger function as an argument. Enumeration functions are prefixed with an enum. For example, the Winex.enum enumeration function can enumerate all the desktop windows.

Io.open ();
Import Winex;
Winex.enum (
    function (hwnd,depth) {
    .. Io.print (Depth,hwnd,win.gettext (HWND);
}
}

All enumerated functions must conform to the Convention at design time: return False to stop the enumeration.

Two. Iteration
Iterative functions are typically used in for...in statements to create an iterator that traverses a collection member. The iteration function is prefixed with each. such as Com.each function, Winex.each function.

Io.open ();
Import Winex;
For Hwnd,title,theadid in  Winex.each () {
    io.print (hwnd,title,theadid);
}

Three. The difference between iterations and enumerations
An iteration is a breadth traversal, usually traversing a collection object at the same depth, iterating through one member of the collection at a time in a loop.
Enumerations can iterate through the collection in a recursive depth and enumerate the elements of the collection at once.

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.