C Programming Tutorial For Beginners 06 selection

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
switch(a) { case 1: printf(“Monday”);
case 2: printf(“Tuesday”); …… case 7: printf(“Sunday”); default : printf(“Input Error”); }
switch-case Selection
use break statement to jump off switch-case selection when necessary.
When a break statement occurs within a switch-case pattern, the execution will jump out of the switch-case from that point.
switch-case Selection Example 3 - 5
switch-case Selection
switch(exp) { case value_1: statement_1
case value_2: statement_2 …… case value_n: statement_n default : statement }
switch-case Selection
Tips
Flags are widely used to keep specific status for further processing.
Conditional Expressions
Conditional expressions (? :), provides an alternate way for if-else selection.
switch-case Selection
switch-case is a useful pattern for multibranch selections based on a valuematching mechanism, which is quite different with if-else selection.
max = ( a > b ) ? a : b; if( a > b )
max = a; else
max = b;
Question? Suggestion?
百度文库
Homework Page 66: Exercise 5, 6, 7, 8
C Programming Language
Lecture 6
Selection II
Outline
Review switch-case Selection Conditional Expressions
Review
Relational Operators Logical Operators if-else selection if- else if -else selection Nested if-else selection
相关文档
最新文档