c语言skipspace,C语言程序设计ppt-Chapter 3 Control Flow(替换中文教材第4章).ppt

C语言程序设计ppt-Chapter 3 Control Flow(替换中文教材第4章)

华中科技大学计算机学院 The C Programming Language The C Programming Language Chapter 3 Control Flow Classification of C statements Statements General Description Purpose: The Control-flow statements of a language specify the order in which computations are performed. Statements: Control-flow statements include Expression statement、block/compound statement、if statement, switch statement、while statement, do-while statement, for statement, label statement and transfer statements which includes break, continue, goto and returnstatement. label statement and transfer statements are rarely used in programming.?? 3.1 Statements and Blocks -Expression statement An expression such as x=0 or i++ or printf(…) becomes a statement when it is followed by a semicolon, as in x= 0; i++; printf(…); In C, the semicolon is a statement terminator, rather than a separator as it is in language like Pascal. Compound statement or block(1) Braces { and } are used to group declarations and statements together into a compound statement, or block, so that they are syntactically equivalent to a single statement. There is no semicolon after the right brace that ends a block. Compound statement or block(2) The braces that surround the statement of a function are one obvious example; Ex. void main(void) { statement sequence } Compound statement or block(3) braces around multiple statements after an if, else, while, or for are another. Ex. int x=1,y=2,z=3; if(x>1){ y++; z = x+y; } Compound statement or block(3) variables can be declared inside any block. Example: { int a = 0, b = 1; { /* this is called nested compound statement */ int a=1; printf(”a=%d\n”, a); /* output 1 */ printf(”b=%d\n”,b += 1); } printf(“a=%d\n”,a); /* output 0 */ printf(“b=%d\n”,b); } 3.2 If-Else The if-else statement is used to express decisions. Formally, the syntax is if(expression) statement1 else statement2 where the else part is optional. First, the expressi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值