Important difference between for each and for next loops.

Category : C#, VB.Net

For Each loops is a read-only loop! In other words, you cannot mutate the reference you are referring to.

A For Next loop allows mutation, plus I like For Next’s because they allow me to determine if I am on the final loop or not…

Examples,

For x as integer = 0 to myStringArray.Count – 1

myStringArray(x) += “add this to end”

if x = myStringArray.Count – 1 then myStringArray(x) += “, and this is the last element!”
Next

cheers!
t

Post a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word