473,569 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Next iteration in a for loop?


Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not
jump out all together.

Thanks!

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com
Nov 21 '05 #1
23 21990
For x = 1 To 10
If something <> 1 Then
...
End If
Next
"Mitchell Vincent" <mv******@newsg roup.nospam> wrote in message
news:uX******** *****@tk2msftng p13.phx.gbl...

Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not jump
out all together.

Thanks!

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com

Nov 21 '05 #2
There is no equivalent of 'continue' in VB. Maybe 2.0 has it, don't know...

"Mitchell Vincent" <mv******@newsg roup.nospam> wrote in message
news:uX******** *****@tk2msftng p13.phx.gbl...

Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not jump
out all together.

Thanks!

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com

Nov 21 '05 #3
Marina wrote:
There is no equivalent of 'continue' in VB. Maybe 2.0 has it, don't know...


I just looked it up and 2.0 *does* have continue - woohoo!
--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com
Nov 21 '05 #4
Version 2.0 has it, but the same underlying logic is available via (gasp)
goto's. I hate goto's as much as the next person, but that *is* what
"Continue For" is in version 2.0. Continue's and exit's (or 'break' in C#)
are all just specialized goto's that do not require a label.
--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Clear VB: Cleans up outdated VB.NET code
Instant C#: Converts from VB.NET to C#
Instant VB: Converts from C# to VB.NET
Instant J#: Converts from VB.NET to J#
"Mitchell Vincent" wrote:

Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not
jump out all together.

Thanks!

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com

Nov 21 '05 #5
"Mitchell Vincent" <mv******@newsg roup.nospam> schrieb:
Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not jump
out all together.


VB 2005 will provide 'Continue' and 'Continue <type of loop>' statements:

<URL:http://groups.google.t o/group/microsoft.publi c.dotnet.langua ges.vb/msg/abe04dd3937bab6 3>

Note that in many cases it's easy to replace 'Continue' by a more structured
'If...Then...El se...' block.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6
In article <OV************ **@TK2MSFTNGP10 .phx.gbl>, Herfried K. Wagner [MVP] wrote:
"Mitchell Vincent" <mv******@newsg roup.nospam> schrieb:
Is there any way to "skip" iterations in a for loop?

Example :

for x = 1 to 10

if something = 1
next
endif

next

I see the Exit For, but I just need to skip iterations sometimes, not jump
out all together.


VB 2005 will provide 'Continue' and 'Continue <type of loop>' statements:

<URL:http://groups.google.t o/group/microsoft.publi c.dotnet.langua ges.vb/msg/abe04dd3937bab6 3>

Note that in many cases it's easy to replace 'Continue' by a more structured
'If...Then...El se...' block.


This is one of the places that I find Goto acceptable. Sometimes. If
you start getting into deeply nested if...then statements, sometimes the
goto can be a little cleaner.

I'm glad they are finally introducint the Continue keyword though, then
I won't feel so bad about it :)

--
Tom Shelton [MVP]
Nov 21 '05 #7
Tom,

I see not any need for a continu or a goto, the sample question askes, is
it possible to skip sometimes a loop in the subject next iteration in a for
loop.

As alternative for Herfrieds 'if else" answer what I agree with, however
that can be complex in a loop.

Do while whatever
select case argument
case 1, 2, 4, 7
case else
'do what not has to be skipped
end select
Next

This the same for a for each loop, a do loop or a for index loop.

Just my thought,

Cor
Nov 21 '05 #8
Cor, I have to disagree with you there. When it's a simple case, then OK,
you can deal with an if or a case statement.

However, many times, the blocks of code in a loop can be quite complex, and
the 'continue' would be burried deeply in there, and it would be very
difficult to structure a way to skip the rest of the loop. Because it's not
always an all or nothing kind of thing - you may need to execute some of the
beginning parts - but not later. And with all the nesting that can occur,
it is difficult to get out of that iteration of the loop.

I think goto's can be avoided far more easily, since the code can be
restructured to have more methods, etc. But I think continue is quite
useful.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Tom,

I see not any need for a continu or a goto, the sample question askes, is
it possible to skip sometimes a loop in the subject next iteration in a
for loop.

As alternative for Herfrieds 'if else" answer what I agree with, however
that can be complex in a loop.

Do while whatever
select case argument
case 1, 2, 4, 7
case else
'do what not has to be skipped
end select
Next

This the same for a for each loop, a do loop or a for index loop.

Just my thought,

Cor

Nov 21 '05 #9

"Marina" <so*****@nospam .com> wrote in message
news:ux******** ******@TK2MSFTN GP15.phx.gbl...
Cor, I have to disagree with you there. When it's a simple case, then OK,
you can deal with an if or a case statement.

However, many times, the blocks of code in a loop can be quite complex,
and the 'continue' would be burried deeply in there, and it would be very
difficult to structure a way to skip the rest of the loop. Because it's
not always an all or nothing kind of thing - you may need to execute some
of the beginning parts - but not later. And with all the nesting that can
occur, it is difficult to get out of that iteration of the loop.

I think goto's can be avoided far more easily, since the code can be
restructured to have more methods, etc. But I think continue is quite
useful.


You can do it without goto's .. remember, there are many ways to code the
same piece of functionality. Give us an example of something that is so
complex'ed with if's, and we (me for one) will write it showing you how to
do it without goto's or continue's. When a continue exists for a language I
am writing in, great, I use it. If it doesn't, it really doesn't slow me
down much. Just the state of mind I'm in while developing, and using the
tools I have available.

Anyways, if the if's are so complex that you can't seem to figure out how to
do it without a goto or some sort, then you may need to rethink the approach
you are taking, maybe the approach you are taking is too complex and can be
simplified?

HTH,
Mythran

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4842
by: DottingTheNet | last post by:
Hi ppl!! just a newbie ques is there something in PL/SQL that skips to the next iteration in the for loop like a next, etc.???? Thnx!!
4
2704
by: Christopher Benson-Manica | last post by:
I have a situation something like this: int foo; for( foo=bar() ; foo <= bar()+1 ; foo++ ) { if( !baz(foo) ) break; /* do stuff with foo */ } The idea is that the loop happens at most twice - once for foo=bar(), and once
2
3549
by: Marc Miller | last post by:
Is there any way in VB to force the next iteration in a For ... next loop other than using a GoTo? I notice that in C++ you can use 'continue' and in other languages there are syntax for this. Am I missing something? For an example, if a = false I don't want the if b = true to execute. for i = 1 to 10
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
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. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7974
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...
0
6284
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
1
2114
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
0
938
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...

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.