《C++程序设计》(英文版) Chapter 6 Topics

Programming in c++ Looping Dale/eems/Headington
1 Looping

Programming in C++ Chapter 6 Topics While Statement Syntax o Phases of Loop Execution Two Types of Loops: Count-Controlled Loops &Event-Controlled Loops s Using the End-of-File Condition to Control Input Data s Using a While Statement for Summing and ounting How to Design Loops %Nested While Loops s Loop Testing and debugging
2 Chapter 6 Topics ❖While Statement Syntax ❖Phases of Loop Execution ❖Two Types of Loops: Count-Controlled Loops &Event-Controlled Loops ❖Using the End-of-File Condition to Control Input Data ❖Using a While Statement for Summing and Counting ❖How to Design Loops ❖Nested While Loops ❖Loop Testing and Debugging

Programming in C++ What is a loop? %A loop is a repetition control structure it causes a single statement or block to be executed repeatedly
3 ❖A loop is a repetition control structure. ❖it causes a single statement or block to be executed repeatedly What is a loop?

Programming in C++ While Statement SYNTAX while( Expression ∥ oop body NOTE: Loop body can be a single statement, a null statement, or a block
4 While Statement SYNTAX while ( Expression ) { . . // loop body . } NOTE: Loop body can be a single statement, a null statement, or a block

Programming in C++ When the expression is tested and found to be false, the loop is exited and control passes to the statement which follows the loop body. WHILE LOOP FALSE Expression TRUE body statement
5 When the expression is tested and found to be false, the loop is exited and control passes to the statement which follows the loop body. WHILE LOOP FALSE TRUE body statement Expression

Programming in C++ A Comparison of If and While IF-THEN SRATEMENT WHILE STATEMENT If (Expression) While(Expression falsetrue false true Statement1 Statement1 Statement2 Statement2
6 A Comparison of If and While If (Expression) Statement1 Statement2 false true While (Expression) Statement1 Statement2 false true IF-THEN SRATEMENT WHILE STATEMENT

Programming in C++ Phases of Loop EXecution 心 Loop entry Iteration 心 Loop test 心 Loop exit o Termination
7 Phases of Loop Execution ❖Loop entry ❖Iteration ❖Loop test ❖Loop exit ❖Termination

Programming in C++ Two Types of Loops count controlled loops repeat a specIfied number of times event-controlled loops some condition within the loop body changes and this causes the repeating to stop
8 Two Types of Loops count controlled loops repeat a specified number of times event-controlled loops some condition within the loop body changes and this causes the repeating to stop

Programming in C++ Count-controlled loop contains o an initialization of the loop control variable an expression to test for continuing the loop o an update of the loop control variable to be executed with each iteration of the body
9 ❖an initialization of the loop control variable ❖an expression to test for continuing the loop ❖an update of the loop control variable to be executed with each iteration of the body Count-controlled loop contains

Programming in C++ Count-controlled Loop int count count 4 m/initialize loop variable while(count>0) ∥ test expression cout≤< count≤≤end;∥ repeated action count update loop variable cout≤<“Done”<<endl; 10
10 int count ; count = 4; // initialize loop variable while (count > 0) // test expression { cout << count << endl ; // repeated action count -- ; // update loop variable } cout << “Done” << endl ; Count-controlled Loop
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《C++程序设计》(英文版) Chapter 5 Topics.ppt
- 《C++程序设计》(英文版) Chapter 4 Topics.ppt
- 《C++程序设计》(英文版) Chapter 3 Topics.ppt
- 《C++程序设计》(英文版) Chapter 2 Topics.ppt
- 《C++程序设计》(英文版) Chapter 1 Topics.ppt
- 《网络互连技术教程》第9章 广播.ppt
- 《网络互连技术教程》第8章 用户数据报协议—UDP.ppt
- 《网络互连技术教程》第7章 CMP和网络状态.ppt
- 《网络互连技术教程》第6章 地址解析.ppt
- 《网络互连技术教程》第5章 子网与超网.ppt
- 《网络互连技术教程》第4章 网络互连协议——IP.ppt
- 《网络互连技术教程》第3章 网络接入技术.ppt
- 《网络互连技术教程》第2章 网络互连体系.ppt
- 《网络互连技术教程》第1章 网络的历史与发展.ppt
- 《网络互连技术教程》第12章 应用服务.ppt
- 《网络互连技术教程》第11章 域名服务系统—DNS.ppt
- 《网络互连技术教程》第10章 传输控制协议—7CP.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第9章 存储过程与触发器.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第8章 视图及其应用.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第7章 索引及其应用.ppt
- 《C++程序设计》(英文版) Chapter 7 Topics.ppt
- 《C++程序设计》(英文版) Chapter 8 Topics.ppt
- 《C++程序设计》(英文版) Chapter 9 Topics.ppt
- 《C++程序设计》(英文版) Chapter 10 Topics.ppt
- 《C++程序设计》(英文版) Chapter 11 Topics.ppt
- 《C++程序设计》(英文版) Chapter 12 Topic.ppt
- 《C++程序设计》(英文版) Chapter 13 Topics.ppt
- 《C++程序设计》(英文版) Chapter 14 Topics.ppt
- 《C++程序设计》(英文版) Chapter 15 Topics.ppt
- 《Java编程技术基础》第一章 面向对象原理与实现.ppt
- 《Java编程技术基础》第二章 Java的实现基础.ppt
- 《Java编程技术基础》第二章习题.doc
- 《Java编程技术基础》第三章 类与对象(一).ppt
- 《Java编程技术基础》第三章习题.doc
- 《Java编程技术基础》第四章 类与对象(二).ppt
- 《Java编程技术基础》第四章习题.doc
- 《Java编程技术基础》第五章 异常与垃圾收集.ppt
- 《Java编程技术基础》第五章习题.doc
- 《Java编程技术基础》第十一章 Java集合框架.ppt
- 《Java编程技术基础》第十一章习题.doc