Home All Groups Group Topic Archive Search About

break statement equivalent in VB?

Author
28 Nov 2007 8:41 AM
Frank Moyles
Need to quickly write a test app in VB, and this involves porting some
C++ code to VB6. I can't seem to find an equivalent of the break
statement - specifically, to allow me to break out of a WHILE loop
(without having to resort to 'goto' etc) - whats the equivalent in VB?

Author
28 Nov 2007 9:49 AM
Alexander Mueller
Frank Moyles schrieb:
> Need to quickly write a test app in VB, and this involves porting some
> C++ code to VB6. I can't seem to find an equivalent of the break
> statement - specifically, to allow me to break out of a WHILE loop
> (without having to resort to 'goto' etc) - whats the equivalent in VB?

None.
Use GoTo, If or Select Case.
Functionally break is a GoTo.

MfG,
Alex
Author
28 Nov 2007 12:11 PM
John K.Eason
In article <474d39be$0$13111$9b4e6***@newsspool2.arcor-online.net>,
mille***@hotmail.com (Alexander Mueller) wrote:

Show quote
> *From:* Alexander Mueller <mille***@hotmail.com>
>
> Frank Moyles schrieb:
> > Need to quickly write a test app in VB, and this involves porting
> > some C++ code to VB6. I can't seem to find an equivalent of the
> > break statement - specifically, to allow me to break out of a
> > WHILE loop (without having to resort to 'goto' etc) - whats the
> > equivalent in VB?
>
> None.
> Use GoTo, If or Select Case.
> Functionally break is a GoTo.
>
> MfG,
> Alex
>

Use a Do....Loop instead and then you can break out of it with 'Exit Do'.

Regards
       John (john@jeasonNoSpam.cix.co.uk) Remove the obvious to reply...
Author
28 Nov 2007 5:35 PM
Alexander Mueller
John K.Eason schrieb:
Show quote
> In article <474d39be$0$13111$9b4e6***@newsspool2.arcor-online.net>,
> mille***@hotmail.com (Alexander Mueller) wrote:
>
>> *From:* Alexander Mueller <mille***@hotmail.com>
>>
>> Frank Moyles schrieb:
>>> Need to quickly write a test app in VB, and this involves porting
>>> some C++ code to VB6. I can't seem to find an equivalent of the
>>> break statement - specifically, to allow me to break out of a
>>> WHILE loop (without having to resort to 'goto' etc) - whats the
>>> equivalent in VB?
>> None.
>> Use GoTo, If or Select Case.
>> Functionally break is a GoTo.
>>
>> MfG,
>> Alex
>>
>
> Use a Do....Loop instead and then you can break out of it with 'Exit Do'.

Oups sorry i mixed up continue and break.
Break of course exists in VB as "Exit For" or "Exit Do".
Thanks for the correction.

MfG,
Alex
Author
28 Nov 2007 3:05 PM
PeterD
On Wed, 28 Nov 2007 10:49:51 +0100, Alexander Mueller
<mille***@hotmail.com> wrote:

>Frank Moyles schrieb:
>> Need to quickly write a test app in VB, and this involves porting some
>> C++ code to VB6. I can't seem to find an equivalent of the break
>> statement - specifically, to allow me to break out of a WHILE loop
>> (without having to resort to 'goto' etc) - whats the equivalent in VB?
>
>None.
>Use GoTo, If or Select Case.
>Functionally break is a GoTo.
>
>MfG,
>Alex

Exit Do

and

Exit For

are both able to do what you want.

You can also prematurely end a function with the exit statement.
Author
28 Nov 2007 5:37 PM
Alexander Mueller
PeterD schrieb:
Show quote
> On Wed, 28 Nov 2007 10:49:51 +0100, Alexander Mueller
> <mille***@hotmail.com> wrote:
>
>> Frank Moyles schrieb:
>>> Need to quickly write a test app in VB, and this involves porting some
>>> C++ code to VB6. I can't seem to find an equivalent of the break
>>> statement - specifically, to allow me to break out of a WHILE loop
>>> (without having to resort to 'goto' etc) - whats the equivalent in VB?
>> None.
>> Use GoTo, If or Select Case.
>> Functionally break is a GoTo.
>>
>> MfG,
>> Alex
>
> Exit Do
>
> and
>
> Exit For
>
> are both able to do what you want.
>
> You can also prematurely end a function with the exit statement.

Thx for correcting me, i thought of 'continue', where there is
no equivalent in VB.

MfG,
Alex
Author
28 Nov 2007 12:55 PM
David Kerber
In article <OJidnbhZQpWgt9DanZ2dnUVZ8uCdn***@bt.com>,
fgmoyles@nospam.com says...
> Need to quickly write a test app in VB, and this involves porting some
> C++ code to VB6. I can't seem to find an equivalent of the break
> statement - specifically, to allow me to break out of a WHILE loop
> (without having to resort to 'goto' etc) - whats the equivalent in VB?

"Exit Do"
"Exit For"
....

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Author
28 Nov 2007 2:24 PM
Jeff Johnson
"Frank Moyles" <fgmoyles@nospam.com> wrote in message
news:OJidnbhZQpWgt9DanZ2dnUVZ8uCdnZ2d@bt.com...

> Need to quickly write a test app in VB, and this involves porting some C++
> code to VB6. I can't seem to find an equivalent of the break statement -
> specifically, to allow me to break out of a WHILE loop (without having to
> resort to 'goto' etc) - whats the equivalent in VB?

As already stated, While/Wend is ancient syntax; avoid it. Use Do/Loop
instead because it gives you Exit Do. The only time you need GoTo is if you
need the equivalent of C's continue statement, because VB has no such thing,
unfortunately.

AddThis Social Bookmark Button