Results 1 to 2 of 2

Thread: How do to run a loop multiple times?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2009
    Posts
    36

    Question How do to run a loop multiple times?

    I read the lines from a textfile into a string array and then I use a foreach loop on the string array. I want to go through the same string array again after the loop reach the end of the string array. How do I accomplish this?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do to run a loop multiple times?

    First up, do you really need to loop through the same data twice? Maybe you do but maybe you don't. Can you possibly perform two tasks inside the loop you already have, rather than looping again?

    If not then you simply need two loops. Either you need two distinct For Each loops that both loop through the array or else you need to nest the For Each loop inside another For loop, whichever is more appropriate. The second option will only work if your doing the same thing to each element both times. In that case you might also consider putting the loop inside a method and calling that twice.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width