[循环语句执行流程.pptVIP

  • 2
  • 0
  • 约2.44千字
  • 约 10页
  • 2017-01-07 发布于北京
  • 举报
[循环语句执行流程

循环语句执行流程 辽宁科技大学 黄建 mtysoft@163.com while语句求和 while语句与自增 for语句的一般格式 回文数 三种循环语句 三种循环语句的比较 continue 语句 学习的方法 课后题:输出数列的值 * * Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. int i = 1, s = 0; while (i = 100) { s = s + i; i = i + 1; } i = 1 s = 0 ,2 ,3 +1 +2 ,… ,99 ,100 ,101 +… +99 +100 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. int i = 0, s = 0; while (i++ = 100) s += i; i = 0 s = 0 ,1 ,2 +1 +2 ,… ,99 ,100 ,101 +… +99 +100 +101 ,102 ① i = 100 必做 真:循环 假:退出 ② i++ 必做 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. for (表达式1; 表达式2; 表达式3) { 语句 } 例如,下面的程序计算1至100的和: for (s = 0, i = 1; i = 100; i++) s += i; Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. a = 456; b = 0; w = a; do { b = b * 10 + a % 10; a = a / 10; }while (a 0); b = 0; a = 456; w = 456; a = 456/10 = 45; b = 0*10+6 = 6; b = 6*10+5 = 65; b = 65*10+4 = 654; a = 45/10 = 4; a = 4/10 = 0; if (b==w) printf(是); else printf(否); 回文数: 66,121,8998,7 不是: 456,67 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. 循环语句比较 i = 100; s = 0; do { s++; } while (i = 9); s = 0; for (i = 100; i = 9; i++) s++; i = 100; s = 0; while (i = 9) s++; Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. while 语句 for 语句 do - while 语句 当循环次数无法确定,需根据某个条件控制循环次数时,通常用 while 语句。 当已经知道循环次数的时候,用 for 语句比较方便。 当需要先执行循环体,后判断循环条件时,用 do - while 语句。 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile . Copyright 2004-2011 Aspose Pty Ltd. for (表达式1; 表达式2; 表达式3) { 语句1; continue; 语句2; } while (表达式) { 语句1; continue; 语句2; } do { 语句1; continue; 语句2; }while (表达式); Evaluation only. Created with Aspose.Slides for

文档评论(0)

1亿VIP精品文档

相关文档