C Programming Language (2nd edition • New version) Chapter 3rd control Flow

Source: Internet
Author: User

Controls the order in which each calculation operation executes.

3.1 Statement and program block{} is a statement terminator, {} is a compound statement (that is, the program block, can always declare a variable), syntactically equivalent to a single statement, 3.2 3.3 if-else statement If-else:else optional, nested automatic inner layer matching, it is recommended to add {} to clarify or change the matching relationship; If-else If-else: Multi-path determination, only one execution; 3.4 switch statement switch (expression) {Case constant expression: statement ...Default: Statement} Multi-path determination, unless a break or return is encountered, each branch is tested for execution; 3.5 while with For loop while (expression)Statementfor (expression 1, expression 2; expression 3)StatementWhen continue is not included, it is equivalent to: expression 1;while (expression 2) {Statementexpression 3;The break and return can terminate the loop, the comma operator has the lowest priority, evaluates from left to right, and sometimes it can be used to turn several consecutive statements into a statement, which is good for a single expression multi-step calculation of the macro, or closely related structures such as element Exchange: Temp=s[i], s[i]=s[j], s[j ]=temp;3.6 Do-while Loop doStatementwhile () 3.7 The break with the continue statement continue used for looping. On while or do-while: perform the test immediately; for: control transfers to the increment loop variable part; Break is used to jump out of the loop and switch;3.8 Goto statement and label Goto label; Label:StatementGoto is theoretically unnecessary, sometimes difficult to understand, as little as possible, can be used to jump out of multiple loops, the label name of the same variable, can be located in the corresponding Goto function before any statement, scope of the entire function;

C Programming Language (2nd edition • New version) Chapter 3rd control Flow

Related Article

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.