Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. A while loop\'s body can contain multiple statements, as long as they are enc

ID: 3621236 • Letter: 1

Question




1.

A while loop's body can contain multiple statements, as long as they are enclosed in braces



True False



2.

A while loop is somewhat limited, because the counter can only be incremented by one each time through the loop.



True False



3.

An initialization expression may be omitted from the for loop if no initialization is required.



True False


4.

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



True False


5.

If you want to stop a loop before it goes through all its iterations, the break statement may be used.



True False



6.

The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon



True False



7.

The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales



True False



8.

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



True False



9.

You may not use the break statement in a nested loop



True False



10.

This means to increase a value by one..



1. decrement

2. increment

3. modulus

4. parse

5. None of these



11.

Something within a while loop must eventually cause the condition to become false, or a(n) __________ results.



1. null value

2. infinite loop

3. unexpected exit

4. compiler error

5. None of these





12

What is the output of the following code segment?

n = 1;
for ( ; n <= 5; )
cout << n << ' ';
n++;




1. 1 2 3 4 5

2. 1 1 1 ... and on forever

3. 2 3 4 5 6

4. 1 2 3 4

5. 2 3 4 5





13.

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



1. do-while

2. while

3. for

4. infinite

5. None of these




14.

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



1. do-while

2. while

3. for

4. infinite

5. None of these





15.

What will the following code display?

int number = 6;
cout << ++number << endl;




1. 0

2. 5

3. 7

4. 6





16.

What will the following code display?

int number = 6
int x = 0;
x = --number;
cout << x << endl;




1. 7

2. 6

3. 5

4. 0





17.

How many times will the following loop display “Hello”?

for (int i = 0; i < 20; i++)
cout << "Hello!" << endl;





1. 21

2. An infinite number of times

3. 19

4. 20





18.

How many times will the following loop display “Hello”?

for (int i = 1; i < 20; i++)
cout << "Hello!" << endl;





1. 20

2. An infinite number of times

3. 19

4. 21



19.

How many times will the following loop display “Hello”?

for (int i = 0; i <= 20; i++)
cout << "Hello!" << endl;





1. 19

2. 21

3. 20

4. An infinite number of times





20.

How many times will the following loop display “Hello”?

for (int i = 20; i > 0; i--)
cout << "Hello!" << endl;




1. An infinite number of times

2. 21

3. 20

4. 19







Explanation / Answer

please rate - thanks

1.
A while loop's body can contain multiple statements, as long as they are enclosed in braces
True False
2.
A while loop is somewhat limited, because the counter can only be incremented by one each time through the loop.
True False
3.
An initialization expression may be omitted from the for loop if no initialization is required.
True False
4.
The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop
True False
5.
If you want to stop a loop before it goes through all its iterations, the break statement may be used.
True False
6.
The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon
True False
7.
The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales
True False
8.
You may nest while and do-while loops, but you may not nest for loops
True False
9.
You may not use the break statement in a nested loop
True False
10.
This means to increase a value by one..
1. decrement
2. increment     however you can specify increment by 2
3. modulus
4. parse
5. None of these
11.
Something within a while loop must eventually cause the condition to become false, or a(n) __________ results.
1. null value
2. infinite loop
3. unexpected exit
4. compiler error
5. None of these
12
What is the output of the following code segment?
n = 1;
for ( ; n <= 5; )
cout << n << ' ';
n++;
1. 1 2 3 4 5
2. 1 1 1 ... and on forever
3. 2 3 4 5 6
4. 1 2 3 4
5. 2 3 4 5
13.
This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
1. do-while
2. while
3. for
4. infinite
5. None of these
14.
If you want a user to enter exactly 20 values, which loop would be the best to use?
1. do-while
2. while
3. for
4. infinite
5. None of these
15.
What will the following code display?
int number = 6;
cout << ++number << endl;
1. 0
2. 5
3. 7
4. 6
16.
What will the following code display?
int number = 6
int x = 0;
x = --number;
cout << x << endl;
1. 7
2. 6
3. 5
4. 0
17.
How many times will the following loop display “Hello”?
for (int i = 0; i < 20; i++)
cout << "Hello!" << endl;
1. 21
2. An infinite number of times
3. 19
4. 20
18.
How many times will the following loop display “Hello”?
for (int i = 1; i < 20; i++)
cout << "Hello!" << endl;
1. 20
2. An infinite number of times
3. 19
4. 21
19.
How many times will the following loop display “Hello”?
for (int i = 0; i <= 20; i++)
cout << "Hello!" << endl;
1. 19
2. 21
3. 20
4. An infinite number of times
20.
How many times will the following loop display “Hello”?
for (int i = 20; i > 0; i--)
cout << "Hello!" << endl;
1. An infinite number of times
2. 21
3. 20
4. 19