Chapter 5 Review (Questions 1-6,14-23,26,28,29,35-37) (due Oct 9, typed)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

2. Describe the difference between pretest loops and posttest loops.

A pretest loop tests the expression before each iteration. Ie. while and for loops. A posttest loop is tested after each iteration and will always execute at least once. Ie. do-while loop

4. What is the difference between the while loop and the do while loop?

A while loop is a pretest loop and will execute only if the test expression is true A do-while loop is a posttest loop and will run its code at least once then check to see if the expression is false.

3. Why are the statements in the body of a loop called conditionally executed statements?

Because the code inside of loop only executes if the condition of the loop is true.

1. Why should you indent the statements in the body of a loop?

Indenting the body of a loop helps separate and identify the surrounding code and the code inside the loop.

15. Each of a repetition of a loop is known as a(n) _____.

Iteration.

5. Which loop should you use in situations where you wish the loop to repeat until the test expression is false, and the loop should not execute is false to begin with?

While loop.

21. A(n) _______ is a variable that is initialized to some starting value, usually zero, and then has numbers added to it in each iteration of a loop.

accumulator

14. The statement or block that is repeated is known as the ____ of the loop.

body.

28. The _______ statement causes a loop to terminate immediately.

break

36. Convert following do-while loop to a while loop: char sure; do { cout << "Are you sure you want to quit? "; cin >> sure; } while( sure != 'Y' && sure != 'N');

char sure; while( sure != 'Y' && sure != 'N'); { cout << "Are you sure you want to quit? "; cin >> sure; }

29. The_______ statement causes a loop to skip the remaining statements in the current iteration.

continue.

19. A(n) ______ is a variable that "counts" the number of times a loop repeats.

counter

35. Convert the following while loop to a do-while loop: int x = 1; while (x > 0) { cout << "enter a number: "; cin >> x; }

do { cout << "enter a number: "; cin >> x; }while(x > 0);

23. The ______loop always iterates at least once.

do-while loop

6. Which loop should you use in situations where you wish the loop the loop repeat until the test expression is false, but the loop should execute at least one time?

do-while loop.

37. Convert the following while loop to a for loop: int count = 0; while(count < 50) { cout << "count is " << count << endl; count++; }

for(int count = 0; count < 50; count++) { cout << "count is " << count << endl; }

18. A loop that does not have a way of stopping is a(n) _____ loop.

infinite

26. Inside the for loop's parentheses, the first expression is the ________, the second expression is the ________, and the third expression is the _____.

initialize expression; test expression; update expression

17. A loop that evaluates its test expression after each repetition is a(n) ____ loop.

posttest

16. A loop that evaluates its test expression before each repetition is a(n) _____ loop.

pretest

20. A(n) _____ is a sum of numbers that accumulates with each iteration of a loop.

running total.

22. A(n) _____ is a special value that marks the end of a series of values.

sentinel


Set pelajaran terkait

ACCT 2100 (W01) - Exam Questions

View Set

Worksheet 18.3: Piercing the Corporate Veil & Corporate Directors and Officers

View Set

The Native American Voice: Mastery Test

View Set

Test 4 - Internet Law, Social Media, and Data Privacy

View Set