Visual Basic Questions and Answers – Repetition Structure – Do Loop Statement

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Repetition Structure – Do Loop Statement”.

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

Answer: a
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. The requirement for repeating the instructions is referred to as the __________
a) Looping condition
b) Conditional statement
c) Iterative statement
d) Initialization statement
View Answer

Answer: a
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. 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
View Answer

Answer: a
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.
advertisement
advertisement

4. 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
View Answer

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

repeat while balance < 250,000 
  interest = balance * rate
  add interest to balance
  add 1 to number of years 
end repeat while

5. 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
View Answer

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

Note: Join free Sanfoundry classes at Telegram or Youtube
repeat
interest = balance * rate
add interest to balance 
add 1 to number of years 
end repeat while balance < 250,000

advertisement

6. 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
View Answer

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

advertisement
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. The __________ in a Do…Loop statement can contain variables, methods, constants, properties and operators.
a) Exit statement
b) Condition
c) Statement
d) Iteration statement
View Answer

Answer: b
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. 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
View Answer

Answer: a
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. 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
View Answer

Answer: b
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. 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
View Answer

Answer: a
Explanation: The instructions in a posttest loop are always processed at least one, since the condition is checked after the loop body is executed at least one. So even if the condition is false, the loop body is executed at least once. Whereas the instructions in a pretest loop is not processed if the condition is false, since the condition is checked before the body of the loop is executed.

Sanfoundry Global Education & Learning Series – Visual Basic.

To practice all areas of Visual Basic, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.