int x = 0;
while (x < 5)
{
cout << x << ' ';
x++;
}
0 1 2 3 4
To write data to a file, you define an object of this data type
ofstream
This is a variable that is regularly incremented or decremented each time a loop iterates
counter
What will the following code display?
7
Assuming dataFile is a file stream object, the statement: dataFile.close();
closes a file
You may not use the break statement in a nested loop
False
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
What will the following code display?
int number = 6;
int x = 0;
x = --number;
cout << x;
5
Assuming outFile is an output file stream object, and number is a variable, which statement writes the contents of number to the file associated with outFile?
outFile << number;
Multiple relational expressions cannot be placed into the test condition of a for loop
True
What is the output of the following code segment?
n = 1;
for ( ; n <= 5; )
cout << n << ' ';
n++;
1 1 1 ... and on, forever
You may nest while and do-while loops, but you may not nest for loops
False
The do-while loop is considered a(n) _________ loop
post-record
What will the following code display?
int number = 6;
int x = 0;
x = number--;
cout << x;
6
When the increment operator precedes its operand, as in ++num1, the operator is in this mode
prefix
The while loop contains 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
The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed
at least once
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
How many times will the following loop display "Hello!"?
for (int i = 0; i < 20; i++)
cout << "Hello!" << endl;
20
You may define a __________ in the initialization expression of a for loop.
variable
Something within a while loop must eventually cause the condition to become false, or a(n) __________ results
infinite loop
If you place a semicolon after the test expression in a while loop, it is assumed to be a(n)
null statement
An output file is a file that data is written to.
True
Look at the following statement: while (x++ < 10)
Which operator is used first?
++
This statement causes a loop to terminate early.
break