Results 1 to 16 of 16

Thread: How do you exit a loop?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    40

    How do you exit a loop?

    huh? HUH!?

  2. #2
    hellswraith
    Guest
    exit for

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    or
    Exit While
    Exit Do

  4. #4
    You can also exit a function or sub with that keyword, so the complete list (according to the VB5 help) is:
    VB Code:
    1. Exit Do
    2. Exit For
    3. Exit Function
    4. Exit Property
    5. Exit Sub
    6. Exit While ' they forgot that

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by filburt1
    VB Code:
    1. Exit While ' they forgot that
    No I didn't

  6. #6
    I mean the VB5 help did.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    Too bad, Exit While no longer works in VB6

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well use a Do While loop instead then.

  9. #9
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    Yes, I've always use DO WHILE loop, instead of WHILE WEND loop. Wondering, is there any difference other than the ability to exit loop.

    Harddisk

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Harddisk
    Yes, I've always use DO WHILE loop, instead of WHILE WEND loop. Wondering, is there any difference other than the ability to exit loop.

    Harddisk
    The main difference is of course that you can put the While statement at the end of the loop and by doing that the loop will execute at least once.

  11. #11
    Why would they kill the While-Wend loop? It's probably one of the most useful ones in any language.

  12. #12
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    Originally posted by filburt1
    Why would they kill the While-Wend loop? It's probably one of the most useful ones in any language.
    filburt1, While Wend is still available, except that you are not able to exit/break from the loop halfway running it.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by filburt1
    Why would they kill the While-Wend loop? It's probably one of the most useful ones in any language.
    The While ... Wend loop is actually sort of depricated. You can always use a Do While .... Loop iteration instead.
    BTW it has changed in VB.Net to While ... End While to be more like any other block statements in VB.

    Best regards

  14. #14
    But as pointed out the two loops have different purposes; even in C++ and Java there's:
    Code:
    do
    {
    
    } while (condition);
    
    // and
    
    while (condition)
    {
    
    }
    So do both loops still exist in VB.Net?

  15. #15
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Also yahs forgot the

    Do Until
    and
    Loop Until

    Example:

    Do until a=5
    Loop Until a=5

    The difference is very small. If you use DO Until then the code will run one last time. If you use loop until it will stop looping immediately.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by filburt1
    But as pointed out the two loops have different purposes; even in C++ and Java there's:
    Code:
    do
    {
    
    } while (condition);
    
    // and
    
    while (condition)
    {
    
    }
    So do both loops still exist in VB.Net?
    In VB you can use a Do loop for both cases.
    VB Code:
    1. Do While condition
    2.     'this is exactly like a While ... WEnd loop
    3. Loop
    4. 'or
    5. Do
    6.      '...
    7. Loop While condition
    Both of these still exists in VB.Net. I as I already mentioned the other While loop still exists it just changed from WEnd to While End.
    VB Code:
    1. 'VB.Net code
    2. While condition
    3.     '...
    4. End While
    Do Until is the exact same thing as Do While Not, it's just a preference of how you want to type it.

    Best regards
    Last edited by Joacim Andersson; Dec 30th, 2001 at 07:33 AM.

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