CS-2250: Starting out with C++: Chapter 5 Quiz

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

The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.

False

You may nest while and do-while loops, but you may not nest for loops.

False

You may not use the break and continue statements within the same set of nested loops.

False

If you want a user to enter exactly 20 values, which loop would be the best to use?

For

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.

For

In a for statement, this expression is executed only once

Initialization

A for statement contains three expressions: initialization, test, and:

Update

This statement causes a loop to terminate early.

break

This statement may be used to stop a loop's current iteration and begin the next one.

continue

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?

outFile << number;

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; }

0 1 2 3 4

What is the output of the following code segment? n = 1; for (; n <= 5; ) cout << n << ' '; n++;

1 1 1 ...and on forever

Look at the following statement. while (x++<10) Which operator is used first?

<

A loop that is inside another loop is called:

A nested loop

A file must be ________ before data can be written to or read from it.

Opened

The do-while loop is considered a(n) ________ loop.

Post-test

How many times will the following loop display "Hello"? for (int i = 0; i < 20, i++) cout << "Hello!" <<endl;

20

How many times will the following loop display "Hello"? for (int i = 0; i <= 20, i++) cout << "Hello!" <<endl;

21

What will the following code display? int x = 0; for (int count = 0; count <3; count++) x += count; cout << x << endl;

3

The while loop has two important parts: an expression that is tested for a true or false value, and:

a statement or block that is repeated as long as the expression is true


Set pelajaran terkait

AMH2020 Exam 3 Questions (From Quizzes 26-30)

View Set

Stem Structures, Functions, and Growth

View Set

Xcel Solutions: North Carolina Life and Health State - Exam Simulator 1 (Part I)

View Set

Ch. 11 Differential Analysis: The Key to Decision Making

View Set