Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

For next loops - question

Status
Not open for further replies.

Grafton54

Computer
May 9, 2005
11
GB
Some of you familiar with C may know the "continue" command, for example:

for (i=0; i<5; i++) // equivalent to For i = 0 To 5 in VB
{
if (some condition)
cpntinue;

some statement;
} // In VB this would say Next i

In this case, if "some condition" is satisfied, then instead of execting "some statement", the program moves on immediately to the next "go-round" in the loop.

I have been looking for a similar function on VB on the internet, but without success. Could anybody confirm whether this functionality is available in VB or not?

Many thanks.
 
Replies continue below

Recommended for you

I think it's very poor programming style to exit a loop prematurely. If you're not going to iterate the number of times specifed by the 'for' statement, then don't use a for loop; use a while loop.

That being said, 'Exit For' is the VB command that you're looking for.



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I think Grafton is looking for a line that checks some condition, if the condition is true then skip down to the "NEXT" statement and continue in the loop. If the condition is flse, then execute the statements inside the loop and then hit the "NEXT" line. If I am correct, then the syntax would be:

For i = 1 to 5
statements
IF condition = true then goto SkipToNext
statements
SkipToNext:
Next

or

For i = 1 to 5
statements
IF condition = false then
statements
EndIf
Next
 
Yes, I did misread the question.

Perhaps the simplest answer would be

For i = 1 to 10
If (Not (SomeCondition)) Then
<execute body of loop>
End If
Next i

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top