Restart at the begining of the for each

Posted on 2009-02-11
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
I am not sure if it is break to restart at the beginning of the for each.
Question by:mathieu_cupryk
    LVL 69

    Expert Comment

    by:Éric Moreau
    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?
    LVL 69

    Expert Comment

    by:Éric Moreau
    also, we normally see the break statement in a switch structure (Case in VB).
    LVL 27

    Accepted Solution

    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

                  ' Do something...
         End If



    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now