#81477 - 2003-01-24 10:48 AM
Continue-Break in FOR-NEXT loops
|
UNIDAD
Lurker
Registered: 2003-01-24
Posts: 2
Loc: IBIZA (SPAIN)
|
Here is my suggestion: 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
|
|
|
|
#81481 - 2003-01-24 06:50 PM
Re: Continue-Break in FOR-NEXT loops
|
Radimus
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.
|
|
Top
|
|
|
|
#81483 - 2003-01-24 07:09 PM
Re: Continue-Break in FOR-NEXT loops
|
Radimus
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
|
|
Top
|
|
|
|
#81486 - 2003-01-28 04:59 PM
Re: Continue-Break in FOR-NEXT loops
|
Wizard
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 )
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
   
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
|
|
|
|
#81489 - 2003-01-29 03:39 PM
Re: Continue-Break in FOR-NEXT loops
|
Richard H.
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
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|