We help IT Professionals succeed at work.

Restart at the begining of the for each

mathieu_cupryk
on
Medium Priority
182 Views
Last Modified: 2012-05-06
I have the following
For Each filename As String In ListofFiles

                If (Path.GetExtension(filename).Equals(".TXT") Or Path.GetExtension(filename).Equals(".txt")) Then
                    break;?
I am not sure if it is break to restart at the beginning of the for each.
Comment
Watch Question

Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
are you converting C# to VB.Net? Usually break is to get out of a structure (outside the For in your case). Can we see the original C# code?
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
also, we normally see the break statement in a switch structure (Case in VB).
Top Expert 2007
Commented:
Well, you can use "Continue For" if you want to skip the item and keep iterating through the loop.


If you want to actually start over, then you will have to do it this way:

Dim ext As String = String.Empty

For i As Integer = 0 to ListOfFiles.Length - 1

     ext = Path.GetExtension(ListOfFiles(i)).ToLower()

     If ext.Equals(".txt")) Then

               i = 0  'reset

     Else
              ' Do something...
     End If

Next

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.