Recursive remember to return

Source: Internet
Author: User

I have defined a method to find the method with the parent node Li of the current node, and then print the class name of this node.

At the beginning, I wrote the following methods:

Function getli (SRC ){
If (SRC. nodename = 'lil ')
Return SRC;
Else
Getli (SRC. parentnode );
}

Src = getli (SRC)

In this case, an error is returned.

Later I discovered that I did not return the recursive data in else.

After modification

Function getli (SRC ){
If (SRC. nodename = 'lil ')
Return SRC;
Else
Return getli (SRC. parentnode );
}

Src = getli (SRC)

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.