i The C Programming language Chapter 5 Control Flow 累日工作室# ◆非常感谢天肆掠市建学院 周锦姝老师
The C Programming Language Chapter 5 Control Flow #黑日工作室# 非常感谢 天津城市建设学院 周锦姝老师
i The C Programming language Chapter 5 Control Flow Chapter 5 Control Flow a Overview of c statements a Selected Construction if switch 日 Loops goto and if while and do while or 口 break and continue
The C Programming Language Chapter 5 Control Flow Chapter 5 Control Flow ❑ Overview of C Statements ❑ Selected Construction ▪ if ▪ switch ❑ Loops ▪ goto and if ▪ while and do while ▪ for ❑ break and continue
The C Programming language Chapter 5 Control Flow 5.1 Overview of c statements .C statements: using a semicolon as a statement terminator ☆ Kinds of c statements EXI fye归 Cor as total=total+limit a=3 switch Corhpour func(trents for(tb group dec as i h]l()~ int x=l,y=2, Z statdgrewhile( OT zX+y hcEcontinue printf( %od”,z) break goto return
The C Programming Language Chapter 5 Control Flow 5.1 Overview of C Statements ❖ C statements: using a semicolon “ ;” as a statement terminator ; ❖ Kinds of C statements: • Expression statements:an expression flowed by “;” • Control statements (9): if( )~else~ switch for( )~ while( )~ do~while( ) continue break goto return branches loops others As total=total+limit ; a=3 ; func( ) ; printf(“Hello,world!\n”) ; • Compound statements:using braces {…} to group declarations and statements ,so that they are syntactically equivalent to a single statement. oThere is no “;” after the right brace. As { int x=1,y=2,z ; z=x+y ; printf(“%d”,z) ; }
The C Programming language Chapter 5 Control Flow 5.2 Selected Construction(if and switch) if statement: has three syntax O. if (expression)statement expr flowchart 0 tatement as: if(x>y) printf( %od,, x) ◆·if( expression statement 1 !0 expr else as: if(x>y)max-X ht1 statement2 else max-y
The C Programming Language Chapter 5 Control Flow 5.2 Selected Construction (if and switch) ❖ if statement: has three syntax ▪ if (expression) statement ▪ flowchart expr statement !0 =0 as : if (x>y) printf(“%d”,x); expr statement1 statement2 !0 =0 ▪ if (expression) statement1 else statement2 ▪ flowchart as:if (x>y) max=x ; else max=y ;
i The C Programming language Chapter 5 Control Flow if expr1) statement l else if(expr2) statement2 else if(expr3) Statement as: if(salary> 1000) dex=0. 4 else if(salary>800) index=0.3 else if(salary> 600 index=0.2 else if(salary>400 index=0.1 else index=0 非0 statemnt1 statemnt2 statemnt3 statemntn
The C Programming Language Chapter 5 Control Flow ▪ if ( expr1 ) statement1 else if (expr2 ) statement2 else if (expr3 ) statement3 …... [ else statement n ] expr1 statemnt1 非0 =0 expr2 expr3 statemnt2 statemnt3 statemntn 非0 非0 =0 =0 ▪ flowchart: as: if (salary>1000) index=0.4; else if (salary>800) index=0.3; else if (salary>600) index=0.2; else if (salary>400) index=0.1; else index=0;