Page 1 of 1 1
Topic Options
#81477 - 2003-01-24 10:48 AM Continue-Break in FOR-NEXT loops
UNIDAD Offline
Lurker

Registered: 2003-01-24
Posts: 2
Loc: IBIZA (SPAIN)
Here is my suggestion:
[Big Grin]
It would be very usefull to have "continue" and "break" statements within FOR-NEXT and WHILE-LOOP structures, as many languages have.
I think this statements make code easier to write and read.

Thanks for your attention.

Top
#81478 - 2003-01-24 11:08 AM Re: Continue-Break in FOR-NEXT loops
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
UNIDAD, all, Ruud,

albeit some of the enthusiastics (aka 'Kixpharts') may cry 'easy to have without intrinsic support !', I'd like to second that request (did it once in another request and do it again) [Big Grin]

J.
_________________________



Top
#81479 - 2003-01-24 11:44 AM Re: Continue-Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I agree.

It is always possible to code around the lack of break/continue, but you can achieve cleaner more elegant (and understandable) code using them.

It'll reduce golf scores too, heh.

Top
#81480 - 2003-01-24 05:13 PM Re: Continue-Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it will make code maybe 2 lines shorter in worst cases.
it makes it easier to write, just like goto but... it does not make it easy to follow.

I'm not against this, but neither I'm for.
_________________________
!

download KiXnet

Top
#81481 - 2003-01-24 06:50 PM Re: Continue-Break in FOR-NEXT loops
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I'd third that as well

I'd also like a 'where' clause in the for each/next statements. the numeric loops already have a 'step' clause.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#81482 - 2003-01-24 06:54 PM Re: Continue-Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
now, where is purely different to continue or break which are similar to goto
_________________________
!

download KiXnet

Top
#81483 - 2003-01-24 07:09 PM Re: Continue-Break in FOR-NEXT loops
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
but it performs the same sort of benefit in removing the if/endif that the break would provide

for $a=0 to 10
if $a=6 break endif
? $a
next

for each $element in $array where $element<>''
? $element
next

and is similar in concept to what a step parameter does
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#81484 - 2003-01-24 07:13 PM Re: Continue-Break in FOR-NEXT loops
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
WHERE and/or UNTIL

for each $element in $array until $element<>''
? $element
next
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#81485 - 2003-01-24 07:18 PM Re: Continue-Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure, but it would keep the readability simpler
and even it would be faster.

and still, as a hater of goto, I keep hating continue.

only places I've missed breaking of for-loops are the places where I need to code com stuff like wmi or adsi.

if the bloody M$ would provide better interfaces, we would never need any breaking of any loops.
_________________________
!

download KiXnet

Top
#81486 - 2003-01-28 04:59 PM Re: Continue-Break in FOR-NEXT loops
Wizard Offline
Hey THIS is FUN
*****

Registered: 2000-12-05
Posts: 264
Loc: Bristol, England
instead of Break, VB has Exit For, it does the same thing, but is easier to understand what is happening. IMO

IF you have Break, are you 'Break'ing the For/If, or a function.

With Exit, you could have a whole host of extras...

Exit If, For, Function, ...

Again, easier to understand.
(sorry if it will put your golf scores back up [Smile] )

W
_________________________
Wizard
There's no place like 127.0.0.1

vb | kix | batch | html | cfm | js | english

Top
#81487 - 2003-01-29 09:49 AM Re: Continue-Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
"break" is already a keyword, so another generic term would need to be chosen. "ExitLoop" or something.

The reason for using a generic "break" (or similar) keyword rather than something explicit like "exit for" is that it is used to break out of a control structure regardless of type.

The benefits may not be obvious until you consider nested control structures, and where you are supporting a count parameter for break.

Some languages support the count parameter (help me out guys, I can't remember which). 'C' does not support it, and there have been a number of times I've been stuck deep in nested loops and cursed it's omission. Usually in network related code for some peculiar reason.

This allows you to break selectively out of nested loops for example:
code:
For
Do
While
ExitLoop 2
Loop
Until
Next

The "2" count will cause the code to break out of two nested loops, i.e. the While/Loop then the Do/Until constructs, but not the For/Next.

Top
#81488 - 2003-01-29 02:42 PM Re: Continue-Break in FOR-NEXT loops
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
the keyword EXIT already exists so one could simply build on it. It already has a dual purpose, to exit a script, or in the case of a UDF to exit the udf only. All that would be required are a few parameters.

EXIT
EXIT {value}
EXIT FOR
EXIT WHILE
EXIT DO
EXIT UDF

You get the picture...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#81489 - 2003-01-29 03:39 PM Re: Continue-Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Not a good idea, for two reasons.

1) In the example in my previous post, what you want to do is break out of two nested loops, both the "while" and the "do" loops. Of course you could have individual "Exit"s for each type of loop, but you are limiting it's functionality and usefulnes.

2) KiXtart is a free format language. "Exit" has an optional parameter. This means that given something a snippet of code like:
code:
Exit Do Until

or the equivalent
code:
Exit
Do
Until

The parser would have to make a decision about how to deal with the code.
Is it an "Exit Do" with the "Until" being related to a "Do" encountered earlier in the script, or is it a solitary "Exit" followed by a Do/Until loop?
It can be done, but it adds unnecessary complexity to the parser for no gain.

As an aside, I have always thought that the exit value for "Exit" and "Quit" should be mandatory, not optional. The syntax is a poor choice in a free format language, and I guess is a historical oddity.

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.12 seconds in which 0.054 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org