Results 1 to 2 of 2

Thread: Nested Loop

  1. #1

    Thread Starter
    Hyperactive Member Art W.'s Avatar
    Join Date
    Apr 2002
    Location
    In My Own Little World, But that’s OK because they know me there!
    Posts
    271

    Nested Loop

    Hello Everyone:

    The following loop starts in x then loops thru y 20 times then goes back and finishes x. how do I get it to loop thru x then complete loop y then loop x once more then loop y completely again 20 times then back to x and another 20 y’s. there should be 200 loops today.

    ? Code:
    1. Do Until X = 10
    2.             X += 1
    3.             MessageBox.Show("Loop X = " & X)
    4.             Do Until y = 20
    5.                 y += 1
    6.                 MessageBox.Show("Loop Y = " & y)
    7.             Loop
    8.  
    9.         Loop
    10.        
    11.     End Sub

    I need to figure this out as part of a larger program.

    Thanks

    Art W.
    SLEEP: A Totally Inadequate Substation For Caffeine!

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

    Re: Nested Loop

    You might want to try resetting 'y' because you aren't even going to enter the inner loop the second time if the value of 'y' is still the same value that caused you to exit the loop in the first place. Besides that, maybe it's just a poor example but those loops should be For loops anyway, not Do loops.
    vb.net Code:
    1. For x = 1 To 10
    2.     For y = 1 To 20
    3.         MessageBox.Show("y = " & y, "x = " & x)
    4.     Next y
    5. Next x
    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

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