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.
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 -
Dim j As Integer
-
For i As Integer = 1 To 4
-
If i = 3 Then Exit For
-
j = i
-
Next i
-
MsgBox(j) ' will give 2
-
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... - For Index = 1 to 10
-
Do
-
If some condition Then
-
Exit Do ' Equivalent of applying Continue to the For loop.
-
End If
-
... other processing that you wanted to skip ...
-
-
Loop While False ' In other words, don't loop.
-
Next
It's a little ugly, but it works.
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.
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 />";
|
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
|
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...
|
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
|
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
| |
by: Dave Cox |
last post by:
of "int" in VB?
//b=1.2
b=int(b)
//b now equals 1
|
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?
|
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
|
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.
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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
| |
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...
| |