Consulting

Results 1 to 4 of 4

Thread: Quick question about loops

  1. #1

    Quick question about loops

    How can I force a do loop to begin the next iteration on a certain condition without finishing the current loop??
    For example if I have something like
     do until a = 5
    if a = 0 then ***
    more code...
    a = a+1
    loop
    So where the *** is i would be telling the loop to stop there and begin the next loop?
    Appreciate any help!

  2. #2
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    nathan2314,

    You could do something like this:
        Do Until a = 5
            If a = 0 Then GoTo LOOP_DONE
    '       more code...
    LOOP_DONE:
            a = a + 1
        Loop
    I think this should get your job done
    Ron
    Windermere, FL

  3. #3
    Ahh that worked perfectly

    Thanks!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why not just

    Do Until b = 10
    'more code...
    b = b + 1
    Loop
    Do Until a = 5
    'more code...
    a = a + 1
    Loop
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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