Home All Groups Group Topic Archive Search About

How to break If statement

Author
29 Nov 2007 8:02 AM
hon123456
Dear all,

          I have if Statement as follows.


      IF a < B Then
               if C < D then break if

               Statement A
               Statement B
               Statement C

      End IF


What I want is when C<D , then the external If statement can be break
and Statement A,B,C is not run. IF C is not < D, then Statement A,B,C
is executed. Can I do that in VB?

Thanks

Author
29 Nov 2007 8:04 AM
Steve Gerrard
Show quote
"hon123456" <peterhon***@yahoo.com.hk> wrote in message
news:9b3253e6-f1d2-4f85-aee0-c11c5598bd85@s36g2000prg.googlegroups.com...
> Dear all,
>
>          I have if Statement as follows.
>
>
>      IF a < B Then
>               if C < D then break if
>
>               Statement A
>               Statement B
>               Statement C
>
>      End IF
>
>
> What I want is when C<D , then the external If statement can be break
> and Statement A,B,C is not run. IF C is not < D, then Statement A,B,C
> is executed. Can I do that in VB?
>
> Thanks
>
>

Normally you would just do

    If A < B Then
        IF D > C Then
            Statement A
            Statement B
            Statement C
        End If
    End If
Author
29 Nov 2007 4:13 PM
PeterD
On Thu, 29 Nov 2007 00:02:25 -0800 (PST), hon123456
<peterhon***@yahoo.com.hk> wrote:

Show quote
>Dear all,
>
>          I have if Statement as follows.
>
>
>      IF a < B Then
>               if C < D then break if
>
>               Statement A
>               Statement B
>               Statement C
>
>      End IF
>
>
>What I want is when C<D , then the external If statement can be break
>and Statement A,B,C is not run. IF C is not < D, then Statement A,B,C
>is executed. Can I do that in VB?
>
>Thanks
>

Well you could try:

   IF a < B Then
      if C < D then
         go to EndIf_01
      else
         Statement A
         Statement B
         Statement C
      end if
   End IF

   EndIf_01:

Or even this ugly mess:

   IF a < B Then
      if C < D then
         ' Do nothing...
      else
         Statement A
         Statement B
         Statement C
      end if
   End IF

Of course the structure of the above example sucks, this code is much
more readable and acceptable:

   IF a < B Then
      if C >= D then
         Statement A
         Statement B
         Statement C
      end if
   End IF

but whatever floats your boat!

AddThis Social Bookmark Button