CHAP06 - Chapter 6 Looping Dale/Weems/Headington 1 Chapter...

Info iconThis preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Chapter 6 Looping Dale/Weems/Headington
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Chapter 6 Topics While Statement Syntax Count-Controlled Loops Event-Controlled Loops Using the End-of-File Condition to Control Input Data Using a While Statement for Summing and Counting Nested While Loops Loop Testing and Debugging
Background image of page 2
3 A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 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
Background image of page 4
5 While Statement SYNTAX while ( Expression ) { . . // loop body . } NOTE:  Loop body can be a single     statement,  a null statement, or a block.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 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
Background image of page 6
7 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
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 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
Background image of page 8
9 Count-controlled Loop int count ; count = 4; while (count > 0) { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT count
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Count-controlled Loop int count ; count = 4; while (count > 0) { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT count 4
Background image of page 10
11 Count-controlled Loop int count ; count = 4; while (count > 0) TRUE { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT count 4
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 Count-controlled Loop int count ; count = 4; while (count > 0) { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT 4 count 4
Background image of page 12
13 Count-controlled Loop int count ; count = 4; while (count > 0) { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT 4 count 3
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 Count-controlled Loop int count ; count = 4; while (count > 0) TRUE { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT 4 count 3
Background image of page 14
15 Count-controlled Loop int count ; count = 4; while (count > 0) { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT 4 3 count 3
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
16 Count-controlled Loop int count ; count = 4; while (count > 0) { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT 4 3 count 2
Background image of page 16
17 Count-controlled Loop int count ; count = 4; while (count > 0) TRUE { cout << count << endl ; count -- ; } cout << “Done” << endl ; OUTPUT 4 3 count 2
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 56

CHAP06 - Chapter 6 Looping Dale/Weems/Headington 1 Chapter...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online