Next iteration in a for loop?

  • Thread starter Thread starter Mitchell Vincent
  • Start date Start date
M

Mitchell Vincent

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!
 
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
 
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,

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 :)
 
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...beats me
why one would type several characters of code when a few would do nicely just
to maintain their "programming religion".. Might want to try Assembler
programming without GoTo's (Jumps as they are sometimes called).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top