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

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

Answer: Option '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.

DigitalOcean Referral Badge

2.

___________________ is a counter-controlled loop.

   A.) For..next loop
   B.) While loop
   C.) If statement
   D.) Do..while loop

Answer: Option 'A'

For..next loop.

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.

DigitalOcean Referral Badge

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.) 6

Answer: Option 'B'

4

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.

DigitalOcean Referral Badge

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

Answer: Option 'C'

12

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.

DigitalOcean Referral Badge

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.) 3

Answer: Option 'B'

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.

DigitalOcean Referral Badge

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.) 8
   C.) 7
   D.) 9

Answer: Option 'A'

10

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.

DigitalOcean Referral Badge

7.

___________ is the process of adding a number to the value stored in a value.

   A.) Counting
   B.) Updating
   C.) Decrementing
   D.) Accumulating

Answer: Option 'B'

Updating

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.

DigitalOcean Referral Badge

8.

______________ in flowchart is used to represent a for clause.

   A.) Circle
   B.) Rectangle
   C.) Parallelogram
   D.) Hexagon

Answer: Option 'D'

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.

DigitalOcean Referral Badge

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.) 2
   D.) 4

Answer: Option 'B'

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.

DigitalOcean Referral Badge

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

Answer: Option 'B'

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.

DigitalOcean Referral Badge

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

Recent Posts