Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net's For Next

Tags:

vb.net

Is there a difference between these?

For i = 0 To Something.Length - 1
  'do something
Next

For i = 0 To Something.Length - 1
  'do something
Next i
like image 219
Louis Waweru Avatar asked Mar 14 '11 10:03

Louis Waweru


People also ask

What is for next in Visual Basic?

You use a For ... Next structure when you want to repeat a set of statements a set number of times. In the following example, the index variable starts with a value of 1 and is incremented with each iteration of the loop, ending after the value of index reaches 5.

What is the use of for next loop?

The for... next statement is an iterative, incremental loop statement used to repeat a sequence of statements for a specific number of occurrences. A for... next loop executes a set of statements for successive values of a variable until a limiting value is encountered.


2 Answers

It is only for readability:

You can optionally specify counter in the Next statement. This improves the readability of your program, especially if you have nested For loops. You must specify the same variable as the one that appears in the corresponding For statement.

From http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx

like image 105
ThiefMaster Avatar answered Oct 12 '22 20:10

ThiefMaster


Nope. There is no difference. Even with nested loops there is no difference because nested for-loops cannot overlap.

like image 20
Bala R Avatar answered Oct 12 '22 19:10

Bala R