473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

vb.net equivalent to c# continue

Does anyone know of the vb.net equivelent to the c# continue so I can exit the immediate iteration of a for loop and continue with the next one.
May 8 '07 #1
7 6270
SammyB
807 Expert 512MB
Does anyone know of the vb.net equivelent to the c# continue so I can exit the immediate iteration of a for loop and continue with the next one.
Exit For
Expand|Select|Wrap|Line Numbers
  1.         Dim j As Integer
  2.         For i As Integer = 1 To 4
  3.             If i = 3 Then Exit For
  4.             j = i
  5.         Next i
  6.         MsgBox(j) ' will give 2
  7.  
May 8 '07 #2
Killer42
8,435 Expert 8TB
Sorry Sammy, close but no cigar. Continue doesn't drop out of the loop, it skips to the next iteration.

In VB6, at least, I don't think there is an equivalent of continue. I seem to recall hearing recently about something in VB.Net which would do it, but don't remember what it was.

In VB6, I tend to use an inner loop to achieve the same end. For example...
Expand|Select|Wrap|Line Numbers
  1. For Index = 1 to 10
  2.   Do
  3.   If some condition Then
  4.     Exit Do ' Equivalent of applying Continue to the For loop.
  5.   End If
  6.   ... other processing that you wanted to skip ...
  7.  
  8.   Loop While False ' In other words, don't loop.
  9. Next
It's a little ugly, but it works.
May 9 '07 #3
SammyB
807 Expert 512MB
> Sorry Sammy, close but no cigar. Continue doesn't drop out of the loop, it skips to the next iteration.

Yep, sorry, I didn't read past "exit"

http://msdn2.microsoft.com/en-us/lib...6t(VS.71).aspx says
"Visual Basic .NET does not support the Continue statement of previous versions of Visual Basic. However, you can achieve the same functionality by putting a statement label on the Loop statement and branching to it from the middle of the loop."

Too bad it's in C#! Makes for ghasty code. And Microsoft's solution of a statement label is just as bad. Just rewrite the loop and make it readable.
May 10 '07 #4
Killer42
8,435 Expert 8TB
Too bad it's in C#! Makes for ghasty code. And Microsoft's solution of a statement label is just as bad. Just rewrite the loop and make it readable.
I partially agree. I love the ability to skip to the next iteration (it's available in the mainframe language that I use) and really miss it in VB. But MS's workaround sounds really ugly.

I'd like to know which "previous versions of VB" they're referring to, as VB6 certainly doesn't have a Continue statement.
May 10 '07 #5
SammyB
807 Expert 512MB
I partially agree. I love the ability to skip to the next iteration (it's available in the mainframe language that I use) and really miss it in VB. But MS's workaround sounds really ugly.

I'd like to know which "previous versions of VB" they're referring to, as VB6 certainly doesn't have a Continue statement.
Those were my thoughts exactly, because I'd tried in VBA and it didn't work there either.
May 11 '07 #6
i don't know where you all get your (out-dated) info. at http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx you can find the VB.NET 'continue' statement which uses an additional 'do', 'for', or 'while':
"Continue For" for the C# equivalent of 'continue' in a for loop.

It was added in Visual Basic 2005 (VB 8). reference: http://en.wikipedia.org/wiki/Visual_Basic_.NET
Mar 1 '13 #7
Killer42
8,435 Expert 8TB
Well, I think the basic problem here is that the question was asked in the pre-dot-net VB forum. Someone (such as myself) really should have directed the poster to the VB.Net forum for more up-to-date info.

Of course this may all be a little late, given this thread is about 6 years old.
Apr 4 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michael Satterwhite | last post by:
I *MUST* be overlooking something obvious. Consider the following code: foreach($_POST as $key=>$value) { print "$key=>$value<br />"; if(! empty($value)) { switch($key) { case "Submit": case...
7
by: Poewood | last post by:
I store all my global functions in modules when using vb. What is the equivelent convention in C#. I am converting a .net compact frmwk project from vb to C#. Thanx, Poe
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a question about a script I'm trying to code and invoke when a button (btnSave) is pressed on the page. This script should only run when a textbox (txtAD) on the...
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
3
by: rss | last post by:
set rowcount 1 select Idnum1,Idnum3 from mytable order by Idnum1 DESC, idnum3 ASC is equivelent to select first(Idnum1),first(idnum3) from mytable order by first(Idnum1) DESC...
10
by: Dave Cox | last post by:
of "int" in VB? //b=1.2 b=int(b) //b now equals 1
23
by: pirata | last post by:
I'm a bit confusing about whether "is not" equivelent to "!=" if a != b: ... if a is not b: ... What's the difference between "is not" and "!=" or they are the same thing?
21
by: Mike N. | last post by:
Can someone tell me if there is a C# equivelent to the VBA 'with' statement that works like this: Set myControl = CommandBars(PopUpToUse).Controls.Add(msoControlButton, before:=5) With...
36
by: mdh | last post by:
May I ask the group this somewhat non-focused question....having now seen "continue" used in some of the solutions I have worked on. ( Ex 7-4 solution by Tondo and Gimpel comes to mind) Is there a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.