note_practical_c_programming_chapter_6

Practical C Programming                                        Chapter 6

Branching statements cause on  section of code to be executed or not executed, depending on a conditional clause.
Looping statements are used to repeat a section of code a number of times or until some condition occurs.

1. if statement
    if (condition)
        statement;
    if the condition is true (nonzero), the statement will be executed, otherwise not.
    relational operators
        Operator    Meaning
        <=        Less than or equal to
        <        Less than
        >        Greater than
        >=        Greater than or equal to
        ==        Equal
        !=        Not equal
    Multiple statements may be grouped by putting them inside curly braces ({}).

2. else statement
    if (condition)
        statement;
    else
        statement;
    write code as clearly and simply as possible

3. How not to use strcmp
    the function strcmp compares two strings, and then returns zero if they are equal or nonzero if they are different  
    /* check to see if string1 == string2 */
    if (strcmp(string1, string2) == 0) {
        statements;
    } else {
        statements;
    }
    not to use   
if (strcm(string1, string2)) {
        statements;
    }

4. Looping statements

5. while statements  
 while (condition) {
        statements;
    }
    The program will repeatedly execute the statement inside the while until the condition becomes false (0)

6. break statement
    suppose we want to add a series of numbers, but we don't know how many numbers are to be added together.
    we use the statement:
        if (condition) {
            break;
        }
    to exit the loop

7. continue statement
    the continue statement is very similiar to the break statement, except that instead of terminating the loop, continue starts re-executing the body of the loop from the top.

8. Assignment anywhere side effect
    c allows the use of assignment statements almost anywhere.
    however, avoid it.
Note: programmers frequently have to modify code that someone else wrote. A good exercise is to take someone else's code and then modify it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值