With the while loop, the body of the loop is ____. a. performed as long as the c
ID: 3816549 • Letter: W
Question
With the while loop, the body of the loop is ____. a. performed as long as the conditional expression evaluates to true b. must produce a boolean result c. always performed at least one time d. must be enclosed in curly braces You must tell the user what value to type to end the loop for ____.
a. counter-controlled loops
b. any type of loop
c. sentinel-controlled loops
d. state-controlled loops
for (int i = 0; i < 10; i++) { Console.WriteLine(“counter ” + i); }
The variable i defined in the program segment above ____
. a. would have a value of 10 if it were printed on the outside of the loop
b. can be displayed prior to the loop program statements
c. is out of scope when the loop terminates
d. creates an error because it is changed in the update portion
for (int i = 0; i < 5; i++) Console.Write(i + “ ”);
Given the code snippet above, how many times will the loop body be executed?
a. 4
b. 5
c. 6
d. 10
for (int i = 0; i < 5; i++) Console.Write(i + “ ”);
The conditional expression used with the for statement ____.
a. must involve a counter
b. is evaluates after the loop body is performed once
c. must evaluate to false in order for the loop body to be executed
d. is written following the first semicolon
for (int outer = 0; outer < 2; outer++) { for (int inner = 0; inner < 3; inner++) { Console.WriteLine("Outer: {0} Inner: {1}", outer, inner); } }
How many lines will be printed for the above nested loop?
a. 2
b. 3
c. 5
d. 6
for (int outer = 0; outer < 2; outer++) { for (int inner = 0; inner < 3; inner++) { Console.WriteLine("Outer: {0} Inner: {1}", outer, inner); } } During the last iteration through the nested loop, what numbers are printed?
a. Outer: 2 Inner 3
b. Outer: 1 Inner: 2
c. Outer: 1 Inner 0
d. Outer: 3 Inner
0 int counter = 0; while (counter < 100) { Console.WriteLine(counter); counter++; }
Looking above, if the loop body was changed from counter++; to counter += 5;, how many times would the loop body be executed?
a. 19
b. 20
c. 99
d. 100
int counter = 0; while (counter < 100) { Console.WriteLine(counter); counter++; }
The first value printed with the program segment above is ____.
a. 0
b.1
c. 99
d. 100
int counter = 0; while (counter < 100) { Console.WriteLine(counter); counter++; } The last value printed with the above program segment is ____.
a. 0
b. 1
c. 99
d. 100
int inner; for (int outer = 0; outer < 3; outer++) { for (inner = 1; inner < 2; inner++) Console.WriteLine(“Outer: {0} Inner: {1}”, outer, inner); } The nested for statement above displays how many lines of output?
a. 2
b. 3
c. 5
d. 6
int loopVariable = 0; do { Console.WriteLine(“Count = {0:}“, ++loopVariable); }while (loopVariable < 5); How many times will be loop body be executed?
a. 0
b. 4
c. 5
d. 6
Explanation / Answer
a. performed as long as the conditional expression evaluates to true.With the while loop, the body of the loop is performed as long as the conditional expression evaluates to true.
Option a is correct. As,
a. counter-controlled loops, You must tell the user what value to type to end the loop for counter-controlled loops.
As end of for by incrementing the value.for (int i = 0; i < 10; i++)
Option b is correct. As, b. can be displayed prior to the loop program statements,
for (int i = 0; i < 10; i++) { Console.WriteLine(“counter ” + i); }
The variable i defined in the program segment above can be displayed prior to the loop program statements. It will run from 0 to 9.
Option b is correct. As, Given the code snippet above, 5 times will the loop body be executed
for (int i = 0; i < 5; i++) Console.Write(i + “ ”);
Given the code snippet above, how many times will the loop body be executed?
b. 5 times, As, i=0,i=1,i=2,i=3,i=4 - total 5 times.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.