Refactoring method 37: Remove control flag (remove control flag)

Source: Internet
Author: User

 

In a series of boolean expressions, a variable carries a "control flag.Replace the control mark with a break or return statement.

Motivation: In a series of conditional expressions, you will often see the control mark used to determine when to stop the conditional check. The trouble caused by such a tag exceeds the convenience it brings. People use such control labels because structured programming principles tell them:ProgramOnly one entry and exit are allowed. The "Single Exit" principle will let youCodeAdds annoying control labels to greatly reduce the readability of conditional expressions. This isProgramming LanguageThe reason for providing break and continue statements: use them to jump out of complicated conditional statements. The effect of removing the control mark is often surprising: the true purpose of the Condition Statement is much clearer.

Practice: 1. The most obvious way to deal with the control mark is to use the break or continue statement.

2Find the control tag value that will allow you to jump out of this logic.

3Find the statement that assigns values to the tag variables, and use the appropriate break or continue statement.

4, After each replacement, compile and test.

 

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.