Question: Question 1 Given the for loop header below, how many times will the loop repeat? for(int counter = 5; counter < 10; counter++) 5 times
Question 1
Given the for loop header below, how many times will the loop repeat?
for(int counter = 5; counter < 10; counter++)
5 times
6 times
2 times
10 times
Question 2
Which of the following loops will calculate the sum of all of the numbers from 1 to 10, including 1 and 10. You can assume that sum has been initialized to a starting value of 0.
for(int counter = 0; counter < 10; counter++)
sum = sum + counter;
for(int counter = 1; counter < 10; counter++)
sum = sum + counter;
for(int counter = 1; counter <= 10; counter++)
sum = sum + counter;
for(int counter = 0; counter <= 10; counter)
sum = sum + counter;
Question 3
Which statement can be used to skip the remainder of the loop body for a single iteration, without exiting the entire loop (that is, the loop may repeat again if the condition is still true)?
break
continue
skip
None of the above
Question 4
If the loop control variable of a while loop is not modified within the body of the loop, the loop will default to incrementing the value by +1 on each iteration.
True
False
Question 5
Given the while loop below, how many times will the loop body execute?
counter = 10;
while (counter < 10)
{
counter = counter - 1;
}
0 times
1 time
9 times
10 times
Question 6
The break statement can be used to provide an alternative exit condition for a loop, as it terminates the loop immediately without returning to evaluate the condition.
True
False
Question 7
Given the for loop header below, how many times will the loop repeat?
for(int i = 10; i > 0; i = i - 3)
10 times
4 times
0 times
The loop is infinite
Question 8
What is the output of the while loop given below?
counter = 5;
while(counter != 0)
{
cout << counter << endl;
counter = counter - 2;
}
All of the integer values from 5 to 1
All of the odd numbers from 5 to 1
The loop is infinite.
Nothing, the loop never begins.
Question 9
If you needed to write a loop whose body should always execute at least one time, and then will repeat conditionally based on user input, which of the C# supported loops would be the most appropriate?
while
do-while
for
None of the above.
Question 10
The do-while and for loops are examples of post-test loops, which test the condition after executing the body for the first time.
True
False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
