Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exit 'While' (any)

    A generic language comment:
    I'm not a big fan of curtailed loops - Exit For, Exit Do, Exit Function etc - but very occasionaly I'll dabble.
    I am a big fan of While/Wend.

    We have available for us in Word 2000 VBA "Exit For" and 'Exit Do", but no "Exit While".
    I'm adept at fudging code to achieve much the same effect, but for the life of me can't think of a sound logic(al) reason not to implement Exit While.

    By placing my While/Wend loop as the outermost structure of a function, and then employing Exit Function, I achieve the same effect as an Exit While, right? So there's no logical reason not to have it.

    My guess is
    (a) another colossal failure of nerve on the part of Microsoft
    ( they were all out golfing that day
    noone will ever need more than 64K/Exit While
    (d) ????

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Exit 'While' (any)

    While condition ... Wend is rather oldfashioned. It's successors are Do While condition ... Loop and Do ... Loop While condition, as well as Do Until condition ... Loop and Do ... Loop Until condition. Each of these allows Exit Do.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exit 'While' (any)

    >While condition ... Wend is rather oldfashioned.
    There you go, Hans, rubbing it in again ... (grin!)

    <pre>Do While condition ... Loop</pre>

    This is my preferred fudge, and is, I think, semantically identical to While/Wend.
    Which leads me to my earlier conclusion that there's no logic reason not to have an "Exit While".

    I can see that the translation/expansion of the quaint singular While/Wend construct to the 2x2=4 options is an advance.
    I suppose that those writing the Exit Do were told not to waste time in retrofitting While.

    I still don't like the idea of branching out of a loop from the interior; only from the head (or tail).
    But then, I'm old-fashioned .....

    I dug out my copy of "The Little Book Of Basic Style" (John M Nevison, 1978), and his chapter 18 is titled "Exit carefully". No While/Wend back then. Just GoTos out of loops!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Exit 'While' (any)

    > I suppose that those writing the Exit Do were told not to waste time in retrofitting While.

    I'm sure that's the way it went.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Exit 'While' (any)

    <hr>I still don't like the idea of branching out of a loop from the interior; only from the head (or tail).<hr>
    and with a While...Wend (or a Do While) you don't need one - just add a boolean variable to your while condition and set it to False when you want the loop to stop.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exit 'While' (any)

    >just add a boolean variable to your while condition
    I agree.
    That's why I'm not in favour of having a time-bomb in the middle of the loop. I like to keep any decisions about terminating the loop where they belong - in the head or tail of the loop, in the loop-control code itself.
    I remain greatly influenced by another Dutchman Edsger Wybe Dijkstra.
    Like Watson and Crick, his paper is not much more than a page long (here), but changed the world, in this case, the world of programming.

Posting Permissions

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