54.4k views
2 votes
What is the difference in execution between the two following sections of code?

'Example 1
intCounter = 0
Do While intCounter < 10
lstOutput.Items.Add(intCounter * intCounter)
intCounter = intCounter + 1
Loop

'Example 2
For intCounter = 0 to 9
lstOutput.Items.Add(intCounter * intCounter)
Next intCounter

a. The loop in the first example will execute one more time than the second example.
b. The first example is an infinite loop.
c. Both loops are executed in an identical manner.
d. The loop in the first example will never be executed.

1 Answer

5 votes

c. Both loops are executed in an identical manner.

Both Example 1 and Example 2 represent loops that iterate from 0 to 9 and perform the same actions. They will execute the same number of times, which is 10 iterations in this case. The loops increment the `intCounter` variable by 1 in each iteration and add the square of `intCounter` to the `lstOutput` control. The only difference between the two examples is the syntax and structure of the loop constructs.

please mark this as the answer, thank you

User Jot Dhaliwal
by
8.4k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.