473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

For ... Next ...

i know that For...Next as a Exit For....
there is any way from the middle of my for...next code to go to the next
item and jump out part of my code , like the same thing that can be done
with exit for, but instead for go to the next item??

Thanks.
Nov 20 '05 #1
14 2020
* "Ale K." <_n******@thanks.com> scripsit:
i know that For...Next as a Exit For....
there is any way from the middle of my for...next code to go to the next
item and jump out part of my code , like the same thing that can be done
with exit for, but instead for go to the next item??


\\\
For ...
...
If ... Then
...
End If
Next
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #2
Hi, There is no built-in keyword to do this (There is in C#, it's continue).
You may need to have a large "If" statement. DO NOT USE GoTo's.

Try the following:

For Foo = Bar To Baz

Do
...
Loop Until True

Next

The ... is for your code, and when you want to skip your code, and go to the
next item, call 'Exit Do'. The Do...Loop will only run once.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Ale K." <_n******@thanks.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
i know that For...Next as a Exit For....
there is any way from the middle of my for...next code to go to the next
item and jump out part of my code , like the same thing that can be done
with exit for, but instead for go to the next item??

Thanks.

Nov 20 '05 #3
Tom:

I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place. In VB.NET for instance, it's entirely
appropriate to use it to break out of a loop. If you use it to solve a
specific problem with one loop, and you simply use it to break out of a
loop, what is the real problem with this? And is writing convoluted IF
logic really more readable, faster, or safer?

Similarly, look at C# where there is no Fall through on a Switch Statement,
using goto to hit a specific case statement is entirely appropriate and even
desireable in many instances. Inside C# by Archer and WhiteChapel makes a
very convincing argument in favor of Goto as long as it's used correctly.
http://www.amazon.com/exec/obidos/tg...glance&s=books

Bill
"Tom Spink" <th**********@ntlworld.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Hi, There is no built-in keyword to do this (There is in C#, it's continue). You may need to have a large "If" statement. DO NOT USE GoTo's.

Try the following:

For Foo = Bar To Baz

Do
...
Loop Until True

Next

The ... is for your code, and when you want to skip your code, and go to the next item, call 'Exit Do'. The Do...Loop will only run once.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Ale K." <_n******@thanks.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
i know that For...Next as a Exit For....
there is any way from the middle of my for...next code to go to the next
item and jump out part of my code , like the same thing that can be done
with exit for, but instead for go to the next item??

Thanks.


Nov 20 '05 #4
On Thu, 30 Oct 2003 14:31:25 -0500, William Ryan wrote:
I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place. In VB.NET for instance, it's entirely


Fortunately for those who hate GoTo, the next version of VB (Whidbey) has a
Continue For statement for just that very purpose.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #5
> I know I'm going to start WWIII with this...

Yes. Yes you are. ;-)
--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Tom:

I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place. In VB.NET for instance, it's entirely appropriate to use it to break out of a loop. If you use it to solve a
specific problem with one loop, and you simply use it to break out of a
loop, what is the real problem with this? And is writing convoluted IF
logic really more readable, faster, or safer?

Similarly, look at C# where there is no Fall through on a Switch Statement, using goto to hit a specific case statement is entirely appropriate and even desireable in many instances. Inside C# by Archer and WhiteChapel makes a
very convincing argument in favor of Goto as long as it's used correctly.
http://www.amazon.com/exec/obidos/tg...067541945/sr=1
-5/ref=sr_1_5/104-0968507-3087124?v=glance&s=books
Bill
"Tom Spink" <th**********@ntlworld.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Hi, There is no built-in keyword to do this (There is in C#, it's

continue).
You may need to have a large "If" statement. DO NOT USE GoTo's.

Try the following:

For Foo = Bar To Baz

Do
...
Loop Until True

Next

The ... is for your code, and when you want to skip your code, and go to

the
next item, call 'Exit Do'. The Do...Loop will only run once.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Ale K." <_n******@thanks.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
i know that For...Next as a Exit For....
there is any way from the middle of my for...next code to go to the next item and jump out part of my code , like the same thing that can be done with exit for, but instead for go to the next item??

Thanks.



Nov 20 '05 #6
Hi, good good. I'd heard rumours of this.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1q*****************************@40tude.net...
On Thu, 30 Oct 2003 14:31:25 -0500, William Ryan wrote:
I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place. In VB.NET for instance, it's
entirely
Fortunately for those who hate GoTo, the next version of VB (Whidbey) has a Continue For statement for just that very purpose.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #7
"William Ryan" <do********@comcast.nospam.net> wrote...
I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place.


William... I think you will find that the admonition about avoiding goto
statements was mostly due to it's being abused. It was used to jump to
something as arbitrary as a "line number." GOTO <label> isn't anywhere near
as meaningless as GOTO 11920 which is how earlier version of BASIC did it
when there were no labels.

The second reason was that they were used to jump huge distances and not to
escape out of a short loop in a routine that fits comfortably on a page in
the editor. "Self-evident" as a concept was lost when code jumped 1000+
lines to some arbitrary numbered spot. Once you got to line 11920 you'd
have to ask yourself "what variables are visible to me now ... and what
values might they have?"

You didn't even gave to GOTO the beginning of the subroutine, you could GOTO
anywhere... every line had a number.

Nov 20 '05 #8
Agreed, and as such, then that's one more reason not to use GoTo. The fact
that there are appropriate uses is based on the current language spec, that
could easily be corrected. Other than loops, the only other instance I can
think of is Fall Through in switch statements.
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1q*****************************@40tude.net...
On Thu, 30 Oct 2003 14:31:25 -0500, William Ryan wrote:
I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place. In VB.NET for instance, it's
entirely
Fortunately for those who hate GoTo, the next version of VB (Whidbey) has a Continue For statement for just that very purpose.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #9
TOTALLY in Agreement with you. I'm not advocating it's use...I just think
that there are two instances where it's appropriate. I personally don't use
it except to break out of loops if I have to write in depth If logic and in
Switch statements to simulate fall through.
"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:gg********************@twister.nyc.rr.com...
"William Ryan" <do********@comcast.nospam.net> wrote...
I know I'm going to start WWIII with this, but although GoTo should be
avoided, it definitely has its place.
William... I think you will find that the admonition about avoiding goto
statements was mostly due to it's being abused. It was used to jump to
something as arbitrary as a "line number." GOTO <label> isn't anywhere

near as meaningless as GOTO 11920 which is how earlier version of BASIC did it
when there were no labels.

The second reason was that they were used to jump huge distances and not to escape out of a short loop in a routine that fits comfortably on a page in
the editor. "Self-evident" as a concept was lost when code jumped 1000+
lines to some arbitrary numbered spot. Once you got to line 11920 you'd
have to ask yourself "what variables are visible to me now ... and what
values might they have?"

You didn't even gave to GOTO the beginning of the subroutine, you could GOTO anywhere... every line had a number.

Nov 20 '05 #10
Hi Ale,

Since no-one's shown it yet...

For I = 1 To 52
DoSomethingAmazing (I)
If I > 26 Then _
Goto MissedTheBoringBit
DoSomethingBoring (I)

MissedTheBoringBit:
Next

Notice that there's a colon after the MissedTheBoringBit label.

Regards,
Fergus

Just a thought - GoTo is very useful to make up for certain deficiencies
in VB syntax. If anyone makes spaghetti these days I would be surprised. But
if they do, they are also doing far worse things in other areas of the code
and are probably beyond remedy anyway.
Nov 20 '05 #11
Fergus:

Excellent example...This is effectively what I was referring to with the
lack of a fall through in a switch/case statement. I don't like GoTo and
have seen it abused ad naseum....and although I totally agree with what you
said, trust me...there are more than a few Spaghetti Chefs out there serving
up Goto DuJour Pasta.

That's the whole problem with stuff like this. GoTo Sucks by and large and
is totally abused. however, everything, EVERYTHING, even <I can't believe
I'm actually saying this> late binding. In the hands of someone who knows
what they are doing and isn't cutting corners, it can bail you out of rare
problem areas. however, too many people like the shortcuts. GoTo is one of
those blindly partisan things...in my CS classes, you'd automatically fail
if you used GoTo (although there isn't any reason I've found in C++ to use
one). But languages have limitations, and the bottom line is coming up with
the best possible solution.

Always love reading your posts because you get the point across in a manner
that's as elegant as it is convincing. your example below is a prime
example ;-)

Cheers,

bill
"Fergus Cooney" <fi*****@post.com> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...
Hi Ale,

Since no-one's shown it yet...

For I = 1 To 52
DoSomethingAmazing (I)
If I > 26 Then _
Goto MissedTheBoringBit
DoSomethingBoring (I)

MissedTheBoringBit:
Next

Notice that there's a colon after the MissedTheBoringBit label.

Regards,
Fergus

Just a thought - GoTo is very useful to make up for certain deficiencies in VB syntax. If anyone makes spaghetti these days I would be surprised. But if they do, they are also doing far worse things in other areas of the code and are probably beyond remedy anyway.

Nov 20 '05 #12
Tom Leylan wrote:
The second reason was that they were used to jump huge distances and
not to escape out of a short loop in a routine that fits comfortably
on a page in the editor. "Self-evident" as a concept was lost when
code jumped 1000+ lines to some arbitrary numbered spot. Once you
got to line 11920 you'd have to ask yourself "what variables are
visible to me now ... and what values might they have?"


ALL the same variables were visible on line 11920 as line 550 in code I
worked on with my "screamer" 8 MHz 8086. These guys were too good to need
separately compiled modules. ;-) Predictably, the company went out of
business because of software reliability issues.

-- Mark
Nov 20 '05 #13
Hi Bill,

|| ... Spaghetti Chefs out there serving up Goto DuJour Pasta.

ROFL.

|| Always love reading your posts .. [more lovely things]

Blush.. Thank you kindly, sir. :-))

Cheers,
Fergus
Nov 20 '05 #14
"Mark Jerde" <ma********@verizon.no.spam.net> wrote...
Tom Leylan wrote:
The second reason was that they were used to jump huge distances and
not to escape out of a short loop in a routine that fits comfortably
on a page in the editor. "Self-evident" as a concept was lost when
code jumped 1000+ lines to some arbitrary numbered spot. Once you
got to line 11920 you'd have to ask yourself "what variables are
visible to me now ... and what values might they have?"


ALL the same variables were visible on line 11920 as line 550 in code I
worked on with my "screamer" 8 MHz 8086. These guys were too good to need
separately compiled modules. ;-) Predictably, the company went out of
business because of software reliability issues.


Hi Mark,

Adding to the chaos BASIC didn't require the explicit declaration of
variables anywhere. And the routine at 11920 could create one that (upon
return) the code at line 550 could just refer to.


Nov 20 '05 #15

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

Similar topics

3
by: Marcel | last post by:
Hello, I'm working on a search application for my website. The website contains a lot of pictures, and a search should return clickable thumbnails. No problems there. My problem started when I...
2
by: Bengt Richter | last post by:
Is this a well known bug that's been fixed? I couldn't find any discussion of it, but maybe my googling's off today ;-/ >>> def foo(): ... it = iter(range(10)) ... while True: ... ...
7
by: simonwittber | last post by:
>>> gen = iterator() >>> gen.next <method-wrapper object at 0x009D1B70> >>> gen.next <method-wrapper object at 0x009D1BB0> >>> gen.next <method-wrapper object at 0x009D1B70> >>> gen.next...
2
by: Deniz Bahar | last post by:
Hi, I'm working with a single linked list and want to delete elements by searching through the list (starting form the HEAD) then finding the element, then doing the following: NewElement =...
9
by: Steven D'Aprano | last post by:
I'm looking for some way to get the next floating point number after any particular float. (Any mathematicians out there: I am aware that there is no "next real number". But floats are not real...
13
by: Joseph Garvin | last post by:
When I first came to Python I did a lot of C style loops like this: for i in range(len(myarray)): print myarray Obviously the more pythonic way is: for i in my array: print i
7
by: fniles | last post by:
In VB 6.0 in the error trapping, we can do "resume next" to continue on the next code. How can we do that in .NET with "Try", "Catch","End Try" ? Thanks
4
by: Neo | last post by:
I found on error resume next doesn't work in for each... e.g. on error resume next for each x in y 'do stuff next if you have an error in for each loop, it falls in infinite loop... it...
0
ADezii
by: ADezii | last post by:
If you want to visit each item in an Array, you have two alternatives: Use a For Each..Next loop, using a Variant to retrieve each value in turn. Use a For...Next loop, looping from the Lower...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.