Lecture5一C语句 绳伟光 微纳电子学系 上海交通大学 2017-03-07 1/68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lecture 5 — C 语句 绳伟光 微纳电子学系 上海交通大学 2017-03-07 1 / 68
提纲 选择语句(Selection Statements) 。if语句 o switch语句 迭代语句 o while语句 。do语句 ●for语句 逗号运算符 跳出循环语句 空语句 2/68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 提纲 1 选择语句 (Selection Statements) if 语句 switch 语句 2 迭代语句 while 语句 do 语句 for 语句 逗号运算符 跳出循环语句 空语句 2 / 68
提纲 选择语句(Selection Statements) ●if语句 ●switch语句 迭代语句 o while语句 odo语句 。for语句 。逗号运算符 。跳出循环语句 ●空语句 3/68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 提纲 1 选择语句 (Selection Statements) if 语句 switch 语句 2 迭代语句 while 语句 do 语句 for 语句 逗号运算符 跳出循环语句 空语句 3 / 68
Statements 。我们已经接触过return语句和表达式语句 。余下的C语句可以分为 ●选择语句(Selection statements):if and switch 。迭代语句(Iteration statements):while,do,for ●跳转语句(Jump statements.:break,continue,goto(re- turn也在此类中) ●其它语句 ●复合语句(Compound statement) o空语句(Null statement) 4/68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Statements 我们已经接触过 return 语句和表达式语句 余下的 C 语句可以分为 选择语句 (Selection statements): if and switch 迭代语句 (Iteration statements): while, do, for 跳转语句 (Jump statements): break, continue, goto (return 也在此类中) 其它语句 复合语句 (Compound statement) 空语句 (Null statement) 4 / 68
if语句 对于==(equality)和=(assignment)的混淆与误用是最常 见的C编程错误 if (i==0).../tests whether i is equal to 0 if (i=0).../assigns o to i,then tests whether the result is nonzero if (0 <i&&i<n).../test whether 0<= i<n (i is inside a range) if (i<0 i>=n).../test the opposite condition (i is outside the range) 5/68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if 语句 对于 == (equality) 和 = (assignment) 的混淆与误用是最常 见的 C 编程错误 if (i == 0) ... / / tests whether i i s equal to 0 if (i = 0) ... / / assigns 0 to i , then tests whether the re sul t i s nonzero if (0 <= i && i < n) ... / / test whether 0 <= i < n ( i i s inside a range) if (i < 0 || i >= n) ... / / test the opposite condition ( i i s outside the range) 5 / 68