Code complete ch.16 control loop

Source: Internet
Author: User
What?

Code snippets that are repeatedly executed (Are you learning programming on the first day)

Why?

Knowing how to use and when to use each cycle is a decisive factor in creating high-quality software.

How? Checks whether an exit loop at the beginning or end of the loop enters the loop.
  • Enter the loop from only one position
  • Keep the initialization code on the front of the loop before the flattening.
  • Use while (true) to process infinite Loops
  • Use more for loops when appropriate
  • When the while loop is more suitable, do not use the For Loop
Processing loop body
  • Use {} to enclose the loop
  • Avoid empty Loop
  • Place the cyclic internal operations at the beginning or end of the loop
  • Only one thing in a loop
Exit Loop
  • The validation cycle can be terminated-simulate it in your mind
  • Make the cyclic termination condition apparent
  • Do not randomly change the subscript of the for loop to terminate the loop
  • Avoid using cyclic subscript outside the loop (dependent on the final value of the subject under the loop)
  • Exit with the break in the while loop, instead of the Boolean flag
  • Use continue to judge at the beginning of the loop
  • If the language supports this function, use a break with a label.
Use cyclic Variables
  • Array and cyclic boundary are represented by integers or enumeration types.
  • Use a meaningful subscript variable name
  • Restrict subscript in this loop
How long should a loop be?
  • As short as possible, clear at a glance
  • Nested control inLayer 3Less
  • Move long loop content to a subroutine

Code complete ch.16 control loop

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.