Chapter 10 Nested Loops EMCQs
Chapter 10 Nested Loops EMCQs
Nested Loops
All MCQs
Tick () the correct option.
1. In a group of nested loops, which loop is executed the most number of times?
a. the outermost loop
b. the innermost loop
c. all loops are executed the same number of times
d. cannot be determined without knowing the size of the loops
Ans. b. the innermost loop
2. Examine the following code. How many times will the nested loop run?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
}
a. 3
b. 6
c. 1
d. 9
Ans. b. 6
4. Examine the following code. Is there anything that will prevent it from processing?
for (int i=1 ; i <= 3; i++) {
for (int j=1 ; j <= 3; j++) {
}
a. No, it is correct
b. No, but it could run forever
c. Yes, it will return a compiler error
d. Yes, but it will show all zeroes in the output
Ans. c. Yes, it will return a compiler error
10. Which of the following code segments will produce this output? (Ignore spacing.)
2
—
—
—
—
—
—
4
—
—
—
—
—
—
6
—
—
—
—
—
—
8
—
—
—
—
—
—
10
—
—
—
—
—
—
12
a. i only
b. i and ii only
c. ii only
d. iii only
Ans. a. i only
The ............... break is used to terminate the outer loop from the
block of inner loop.
1. level
2. labelled
3. unlabelled
4. forced
Answer
Labelled
1. continue
2. void
3. break
4. stop
Answer
Break
1. 12 times
2. 8 times
3. 4 times
4. 16 times
Answer
12 times
Which of the following statements is not valid for a nested loop?
Answer
The inner loop can be terminated from the block of outer loop.
Answer: for(; ;)
7.) Which of the following looping statements end with a semi-colon (;)
Do-while loop
Infinite loop
Single statement
Group of statement
Infinite loop
Finite loop
None of these
Counter-controlled loop
None of these
29.) In counter-controlled loop, variable known as ________ is used to count the loop
operations.
Counter
Condition
Update variable
None of these
30.) In an exit-controlled loop, if the body is executed n times, the test condition is
evaluated ______ times.
n-1
n+1
None of these
Answer:current iterration
Answer:nested if structure