Results 1 to 6 of 6

Thread: control structure in VB ( and, continue, do...while )

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    3

    control structure in VB ( and, continue, do...while )

    how to convert these control structure java code to VB?

    1. and (&&) in "if"

    if( i < 10 && b[i] < 5 ) // note, if i >=10, java does not check b[i]<5
    {
    ...
    }

    2. dose vb have "continue"?

    for( int i=0; i<10; i++)
    {
    if( a<10)
    continue;

    ...
    }


    3.

    do
    {

    } while( i<10 && a[i] <5 );

    thanks! -Zhining

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    VB Code:
    1. ' 1.
    2.  
    3.     If i < 10 And b(i) < 5 Then
    4.  
    5.         ' Do stuff
    6.    
    7.     End If
    8.  
    9. ' 2.
    10.  
    11.     Do While (a < 10)
    12.  
    13.         ' Do stuff
    14.  
    15.     Loop
    16.  
    17. ' 3.
    18.  
    19.     Do
    20.  
    21.         ' Do stuff
    22.  
    23.     Loop While (i < 10 And a(i) < 5)

  3. #3
    AIS_DK
    Guest
    1.
    if( i < 10 && b[i] < 5 ) // note, if i >=10, java does not check b[i]<5
    {
    ...
    }
    Code:
    if (i < 10) AND (b(i) < 5) then
      'Do something
    end if
    2.
    for( int i=0; i<10; i++)
    {
    if( a<10)
    continue;

    ...
    }
    Code:
    For i=0 to 9
       'Continue isn't a part of vb, but the test could be written like this
       if a >= 10 then exit for 'This will break the for loop
       
    next i
    3.do
    {

    } while( i<10 && a[i] <5 );
    Code:
    do
    
    loop while (i < 10) AND (a(i) < 5)
    That should do it

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    3
    thanks Rudgej and AIS_DK for you quick responses!!!

    But I still have the problem "of and in if". Please look at the following code. I got an error.

    In java and C, if i>=3, it won't check a( i) > 99, so no problem in java.

    thanks!

    ===================
    Dim a(3) As Integer
    Dim i As Integer

    i = 10
    If i < 3 And a(i) > 99 Then ' script out of range, since i >= 3
    MsgBox "hello"
    End If
    ==================

  5. #5
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    VB Code:
    1. Dim a(3) As Integer
    2. Dim i As Integer
    3.  
    4. i = 10
    5. If i < 3 Then
    6.     If a(i) > 99 Then
    7.         MsgBox "hello"
    8.     End If
    9. End If
    In VB it checks all conditions of the contditional before it decides what's true and what's not. Completely opposite from every other language on the planet This should work for you.
    -Excalibur

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    3

    Red face

    thanks, Excalibur!

    My VB code will be longer than java code, and it is much harder to maintain.

    Thanks again for your helps!

    -Zhining

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