473,856 Members | 2,133 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
23 22025
Marina,

Give us the challenge Mythran gave and probably we both will take it

By the way I am busy with a sample for that MSHTM, I see now it is quit
easy.

Still interested?

(Completely get a page from internet and get the innertext).

:-)

Cor

Nov 21 '05 #11
I didn't say it cannot be done. I said, the work involved is not worth the
inconvenience of having to use 'continue'. And it would probably involve
extra variables, and extra checks. Example:

While (someCondition)
If var1=1 Then
DoThisFirst()

If var2 = 2 Then
DoStuff()
ElseIf var3 = 5 Then
Continue
End If

DoSomeMoreStuff ()
Else
DoThisOtherThin g()
End If

SomeMoreCodeHer e()
End While

Now, you can rewrite it of course, but it will be a lot less easy to
understand exactly what is going on.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:e$******** ******@TK2MSFTN GP11.phx.gbl...
Marina,

Give us the challenge Mythran gave and probably we both will take it

By the way I am busy with a sample for that MSHTM, I see now it is quit
easy.

Still interested?

(Completely get a page from internet and get the innertext).

:-)

Cor

Nov 21 '05 #12
Cor Ligthert [MVP] wrote:
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.


I'm not sure who said it but "A goo programming language should make
easy things easy and hard things possible" - continue should be there
(regardless of how it is implemented) for those cases, rare as they may
be, that nothing else will do.

Yes you can get around using them, but I'd rather spend as little time
possible working around language constructs that aren't there!

Thanks Cor, I appreciate your seemingly infinte insight into all things
..NET! :-)

--
- Mitchell Vincent
- kBilling - Invoices Made Easy!
- http://www.k-billing.com
Nov 21 '05 #13
In article <uO************ **@TK2MSFTNGP10 .phx.gbl>, Mythran wrote:

"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?


There are always ways around goto. No one is arguing that (at least, I
don't think anyone is :). But, it has to be asked - is it worth it?

I've been through the computer sci indoctination myself - and I have a
general distaste for Goto. But, on a rare occasion using a goto can
simplify code. Anyway, this is a topic that brings out a sort of
"religious" extreamism in most programmers, so is probably counter
productive in the long term :)

--
Tom Shelton [MVP]
Nov 21 '05 #14
In article <#M************ *@TK2MSFTNGP11. phx.gbl>, Cor Ligthert [MVP] wrote:
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


Cor,

I am certainly not stating that continue (or goto) are ever needed, they
aren't. There is always a way to write code in such a way as to make
them unnecessary - but, there are times when having these types of tools
makes the code a little cleaner. And believe me, if I will always use a
continue over a goto :)

--
Tom Shelton [MVP]
Nov 21 '05 #15
I've been programming (both as hobby and at times professionally) before most
of you were born and I find GoTo's very useful in some situations...be ats me
why one would type several characters of code when a few would do nicely just
to maintain their "programmin g religion".. Might want to try Assembler
programming without GoTo's (Jumps as they are sometimes called).
--
Dennis in Houston
"Tom Shelton" wrote:
In article <#M************ *@TK2MSFTNGP11. phx.gbl>, Cor Ligthert [MVP] wrote:
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


Cor,

I am certainly not stating that continue (or goto) are ever needed, they
aren't. There is always a way to write code in such a way as to make
them unnecessary - but, there are times when having these types of tools
makes the code a little cleaner. And believe me, if I will always use a
continue over a goto :)

--
Tom Shelton [MVP]

Nov 21 '05 #16
Dennis,

C is already an older language as Cobol is. It started at the time Goto Less
programming became a topic.

http://www.acm.org/classics/oct95/

Therefore there are in that language old elements as we see them in
assembler languages (Branch conditional and unconditional).

That should not mean that they should not be avoided. In Cobol is an "Alter"
statement which has in fact the same effect as changing an address in a
branch statement. No Cobol programmer would use that statement after the
90's

However some C programmers see this as a religion and want to keep there old
C style programming in all from C derived languages.

That should in my opinion not mean that VB programmers should do that as
well.

AFAIK is Pascal created as a counterpart for this old style C programmers.

Just my opinion,

Cor.

Nov 21 '05 #17
Marina,

In the sample I was making for mshtml is almost the same code as you
describe (the last part). Do you mind that I show you that instead of doing
that with your sample.

If you want I will make it with your code as well.

http://www.windowsformsdatagridhelp....f-56dbb63fdf1c

I hope it gives some extra's as well.

Cor

"Marina" <so*****@nospam .com> schreef in bericht
news:Oc******** ******@TK2MSFTN GP15.phx.gbl...
I didn't say it cannot be done. I said, the work involved is not worth the
inconvenienc e of having to use 'continue'. And it would probably involve
extra variables, and extra checks. Example:

While (someCondition)
If var1=1 Then
DoThisFirst()

If var2 = 2 Then
DoStuff()
ElseIf var3 = 5 Then
Continue
End If

DoSomeMoreStuff ()
Else
DoThisOtherThin g()
End If

SomeMoreCodeHer e()
End While

Now, you can rewrite it of course, but it will be a lot less easy to
understand exactly what is going on.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:e$******** ******@TK2MSFTN GP11.phx.gbl...
Marina,

Give us the challenge Mythran gave and probably we both will take it

By the way I am busy with a sample for that MSHTM, I see now it is quit
easy.

Still interested?

(Completely get a page from internet and get the innertext).

:-)

Cor


Nov 21 '05 #18
Huh? What are you talking about?

That was an example of code that would be difficult and error prone to
rewrite without a 'continue'.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:eV******** ********@TK2MSF TNGP12.phx.gbl. ..
Marina,

In the sample I was making for mshtml is almost the same code as you
describe (the last part). Do you mind that I show you that instead of
doing that with your sample.

If you want I will make it with your code as well.

http://www.windowsformsdatagridhelp....f-56dbb63fdf1c

I hope it gives some extra's as well.

Cor

"Marina" <so*****@nospam .com> schreef in bericht
news:Oc******** ******@TK2MSFTN GP15.phx.gbl...
I didn't say it cannot be done. I said, the work involved is not worth
the inconvenience of having to use 'continue'. And it would probably
involve extra variables, and extra checks. Example:

While (someCondition)
If var1=1 Then
DoThisFirst()

If var2 = 2 Then
DoStuff()
ElseIf var3 = 5 Then
Continue
End If

DoSomeMoreStuff ()
Else
DoThisOtherThin g()
End If

SomeMoreCodeHer e()
End While

Now, you can rewrite it of course, but it will be a lot less easy to
understand exactly what is going on.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:e$******** ******@TK2MSFTN GP11.phx.gbl...
Marina,

Give us the challenge Mythran gave and probably we both will take it

By the way I am busy with a sample for that MSHTM, I see now it is quit
easy.

Still interested?

(Completely get a page from internet and get the innertext).

:-)

Cor



Nov 21 '05 #19
Marina,

Reading it over, as always, you are right,

:-)

Therefore see bellow.

Probably this is not the one you want.

\\\See the real one behind this
While condition
While 1 = 1 'faking
If var1 = 1 Then
Dim v1 As Integer = 1 + 1
If var2 = 2 Then
Dim v2 As Integer = 1 + 1
ElseIf var3 = 5 Then
Exit While
End If
Dim v3 As Integer = 1 + 1
Else
Dim v4 As Integer = 1 + 1
End If
Dim v As Integer = 1 + 1
End While
End While
///

\\\ However I find this more readable
While condition
If var1 = 1 Then
Dim v1 As Integer = 1 + 1
If var2 = 2 Then
Dim v2 As Integer = 1 + 1
ElseIf var3 <> 5 Then
Dim v3 As Integer = 1 + 1
End If
Else
Dim v4 As Integer = 1 + 1
End If
If var3 <> 5 Then
Dim v As Integer = 1 + 1
End If
End While
///

I have not really tested the last one.
However the point is the extra condition which tell when it should be done.

Cor
Nov 21 '05 #20

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

Similar topics

1
4865
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
2714
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
3561
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
9754
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
11047
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...
0
10375
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
9526
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
7927
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
7084
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5754
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...
0
5953
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
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 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.