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

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

1. ## 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. VB Code:
`' 1.     If i < 10 And b(i) < 5 Then         ' Do stuff        End If ' 2.     Do While (a < 10)         ' Do stuff     Loop ' 3.     Do         ' Do stuff     Loop While (i < 10 And a(i) < 5)`

3. 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. 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. VB Code:
`Dim a(3) As Integer Dim i As Integer  i = 10 If i < 3 Then    If a(i) > 99 Then        MsgBox "hello"     End IfEnd 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.

6. thanks, Excalibur!

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

-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
•

Featured