Engineering Questions with Answers - Multiple Choice Questions

# MCQs on Repetition Structure – Do Loop Statement

1 - Question

Programmers use __________ known as loops.
a) Repetition structure
b) Conditional structure
c) Goto
d) Unconditional structure

Explanation: Programmers use the repetition structure, referred to more simply as a loop, when they need the computer to repeatedly process one or more program instructions. If and for how long the instructions are repeated is determined by the loop’s condition.

2 - Question

The requirement for repeating the instructions is referred to as the __________
a) Looping condition
b) Conditional statement
c) Iterative statement
d) Initialization statement

Explanation: The requirement for repeating the instructions is referred to as the looping condition, because it indicates when the computer should continue “looping” through the instructions.

3 - Question

The requirement for not repeating the instructions is referred to as the __________
a) Loop exit condition
b) Looping condition
c) Conditional statement
d) Iterative statement

Explanation: The requirement for not repeating the instructions is referred to as the loop exit condition, because it tells the computer when to exit (or stop) the loop. Every looping condition has an opposing loop exit condition; in other words, one is the opposite of the other.

4 - Question

In a __________ loop the condition is evaluated before the instructions within the loop are processed.
a) Posttest
b) Pretest
c) Conditional loop
d) Unconditional loop

Explanation: In a pretest loop, the condition is evaluated before the instructions within the loop are processed. For example,

```repeat while balance &lt; 250,000
interest = balance * rate
add 1 to number of years
end repeat while```

5 - Question

In a __________ loop the condition is evaluated before the instructions within the loop are processed.
a) Posttest
b) Pretest
c) Conditional loop
d) Unconditional loop

Explanation: In a posttest loop, the condition is evaluated after the instructions within the loop are processed. For example,

```repeat
interest = balance * rate
add 1 to number of years
end repeat while balance &lt; 250,000```

6 - Question

The __________ is used to code both pretest and posttest loops.
a) Do loop statement
b) For loop statement
c) While loop statement
d) If statement

Explanation: The do..loop statement is used to code both pretest and posttest loops. For example,
Pretest:

```Do {While | Until} condition
loop body instructions, which will be processed either
while the condition is true or until the condition becomes true
Loop```

Posttest:

```Do
loop body instructions, which will be processed either
while the condition is true or until the condition becomes true
Loop {While | Until} condition```

7 - Question

The __________ in a Do…Loop statement can contain variables, methods, constants, properties and operators.
a) Exit statement
b) Condition
c) Statement
d) Iteration statement

Explanation: The condition in a Do . . . Loop statement can contain variables, constants, properties, methods, keywords, and operators; it also must evaluate to a Boolean value. The condition is evaluated with each repetition of the loop and determines whether the computer processes the loop body.

8 - Question

How many times will the MessageBox.Show method in the following code be processed?

```intCount =0
Do While intCount > 3
MessageBox.Show("Hello")
intCount = intCount + 1
Loop```

a) 0
b) 1
c) 3
d) 4

Explanation: Since intCount is initialized to zero, the condition in the Do while statement will be false, and since the body of the loop will be executed, only if the condition is true, thus it will not be executed even once. Thus Messagebox.Show method will not be processed even once.

9 - Question

How many times will the MessageBox.Show method in the following code be processed?

```intCount =0;
Do
MessageBox.Show("Hello")
intCount += 1
Loop While intCount > 3```

a) 0
b) 1
c) 3
d) 4

Explanation: Since it is posttest, thus the body of the loop will be executed at least once, even if the condition is false. Thus, here since the condition is false, the body of the loop will be executed once, and thus MessageBox.Show will be processed only once.

10 - Question

The instructions in a __________ loop are always processed at least once, whereas the instructions in a __________ loop might not be processed at all.
a) Posttest, pretest
b) Pretest, posttest
c) Pretest, pretest
d) Posttest, posttest