# 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

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.

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

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

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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

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

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.

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

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

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.

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

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

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

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.

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