C + + 's "Control structure"

Source: Internet
Author: User

comparison of the IF statement and the switch statement1. If statement:often used in small branches of the occasion;can be used to determine whether a value is within a range;    2. Switch statement:often used for more branches of the occasion;constants that require their corresponding branches must be strictly equal to a certain value;
3, Summary: if the range of values is large, it is clear that the IF statement is superior to the switch statement. When the value of an expression is a real number, only the IF statement is usually used.
comparison of the while statement and the Do...while statement1. While statement (as type):first judge, after the execution of the loop body;loops may not be executed at once;there is no semicolon after the while condition expression;
2. Do...while statement (until type):first the loop body is executed, then the value of the conditional expression is judged;Be executed at least once under any conditions;The while conditional expression is followed by a semicolon;
3, Summary: the while statement and do ... While statements are commonly used looping statements, but the order of execution and the number of executions are different.
the difference between a break statement and a continue statement1. Break statement:It can be used not only in the circulation body, but also in the swith .... case;interrupt the loop and jump to the level of the loop outside the body;
2. Continue statement:can only be used in the circulation body;interrupt the loop and jump to the outer body of the cycle;
3, Summary: both the break statement and the continue statement have an interruption, but their respective scopes of use and scope vary.

C + + 's "Control structure"

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.