473,671 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net equivalent to c# continue

1 New Member
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 6282
SammyB
807 Recognized Expert Contributor
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 Recognized Expert Expert
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 Recognized Expert Contributor
> 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 Recognized Expert Expert
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 Recognized Expert Contributor
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
humilulo
1 New Member
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 Recognized Expert Expert
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
2694
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 "keyList": case "curKey": print "Matched exception<br />";
7
22063
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
2554
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 page is left blank. I tried to use a code snippet with the "return confirm" function but without success. The code should check whether the textbox is empty or not, and if empty, it should ask the user to continue and then run the next code. How...
8
8488
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 a way to get it from a static method in an aspx page, or in the class (static) constructor for an aspx page? Thanks, Bryan
3
1529
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 ,first(Idnum3) ASC Isn't that silly? why did Microsoft not add an agregate function First for the Microsoft SQL Server to be consistent with its Microsoft Access
10
1840
by: Dave Cox | last post by:
of "int" in VB? //b=1.2 b=int(b) //b now equals 1
23
1706
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
2527
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 myControl .BeginGroup = True .Caption = "Insert Row(s)" .OnAction = "InsertRows" .FaceId = 295
36
2642
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 good principle/s for the good usage of "continue"...or...do any of the regular/irregular contributors have a "favorite" way in which it is particularly useful. Thanks as usual.
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8672
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7441
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.