Visual Basic Questions and Answers – Repetition Structure – For..Next Statement

«
»

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

1. A ____________ loop is a loop whose processing is controlled by a counter.
a) Counter-controlled
b) Entry-controlled
c) Exit-controlled
d) Accumulator-controlled
View Answer

Answer: a
Explanation: A counter-controlled loop is just what its name implies is a loop whose processing is controlled by a counter. You use a counter-controlled loop when you want the computer to process the loop instructions a precise number of times.
advertisement

2. ____________________ is a counter-controlled loop.
a) For..next loop
b) Do..while loop
c) While loop
d) If statement
View Answer

Answer: a
Explanation: For . . . Next statement to code a specific type of pretest loop, called a counter-controlled loop. You also can use the Do . . . Loop statement to code a counter-controlled loop, the For . . . Next statement provides a more compact and convenient way of writing that type of loop.

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

For intCount As Integer = 4 To 11 Step 2
    MessageBox.Show("Hello")
Next intCount

a) 3
b) 4
c) 5
d) 8
View Answer

Answer: b
Explanation: The MessageBox.Show method will be processed only when the condition is satisfied. The body of the loop is executed four times, thus the MessageBox.Show method is processed four times, after which the condition is not satisfied, and it comes out of the loop.
advertisement

4. What value is stored in the intCount variable when the loop ends?

For intCount As Integer = 4 To 11 Step 2
MessageBox.Show("Hello")
Next intCount

a) 10
b) 11
c) 12
d) 13
View Answer

Answer: c
Explanation: At first, intCount contains value 4. It enters the loop and MessageBox.Show is processed and “Hello” is shown. Then the value of count is incremented by 2 i.e. intCount becomes 6.This process is repeated, till intCount becomes 12 and the condition is not satisfied. It does not satisfy the condition, thus it comes out of the loop. Thus the value stored in the count variable when the loop ends is 12.

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

For count As Integer = 5 to 9 Step 5
MessageBox.Show(“Hi”)
Next count

a) 0
b) 1
c) 2
d) 4
View Answer

Answer: b
Explanation: The MessageBox.Show method will be processed only when the condition is satisfied. The body of the loop is executed once, thus the MessageBox.Show method is processed only once, after which the condition is not satisfied, and it comes out of the loop.
advertisement

6. What value is stored in the count variable when the loop ends?

For count As Integer = 5 to 9 Step 5
MessageBox.Show(“Hi”)
Next count

a) 10
b) 9
c) 8
d) 7
View Answer

Answer: a
Explanation: At first, count contains value 5. It enters the loop and MessageBox.Show is processed and “Hi” is shown. Then the value of count is incremented by 5 i.e. count becomes 10. It does not satisfy the condition, thus it comes out of the loop. Thus the value stored in the count variable when the loop ends is 10.

7. ____________ is the process of adding a number to the value stored in a value.
a) Counting
b) Updating
c) Accumulating
d) Decrementing
View Answer

Answer: b
Explanation: Updating is the process of adding a number to the value stored in a counter or
accumulator variable. It is also called incrementing. We increment the value in the loop. In the for loop statement, we can increment the variable as required.
advertisement

8. _______________ in flowchart is used to represent a for clause.
a) Circle
b) Rectangle
c) Parallelogram
d) Hexagon
View Answer

Answer: d
Explanation: Many programmers use a hexagon to represent the For clause.Inside
the hexagon, you record the counter variable’s name and its startValue, stepValue, and endValue.

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

For intNum As Integer = 5 To 1 Step -1
MessageBox.Show(“Hi”)
Next intNum

a) 6
b) 5
c) 4
d) 7
View Answer

Answer: b
Explanation: The MessageBox.Show method will be processed only when the condition is satisfied. The body of the loop is executed five times, thus the MessageBox.Show method is processed five times, after which the condition is not satisfied, and it comes out of the loop.

10. What value is stored in the intNum variable when the loop ends?

For intNum As Integer = 5 To 1 Step -1
MessageBox.Show(“Hi”)
Next intNum

a) 0
b) 1
c) 2
d) 3
View Answer

Answer: a
Explanation: At first intNum contains value 5. It enters the loop and MessageBox.Show is processed and “Hi” is shown. Then the value of count is decremented by 1 i.e. count becomes 4. This process continues, till intNum becomes 0, when the condition is not satisfied. It does not satisfy the condition, thus it comes out of the loop. Thus the value stored in the count variable when the loop ends is 0.

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.

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!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn