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

Registered: 2003-01-24
Posts: 2
Loc: IBIZA (SPAIN)
Hello !!

I am new at Kixtart. I discovered it at Microsoft Resource Kit, and found it very interesting.

Here is my question: [Confused]

Are there any "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
#35635 - 2003-01-24 10:39 AM Re: Continue and Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
No, there aren't. [Frown]

It is on the wish-list. Search the "Suggestions" forum for the last post asking for continue/break and add your voice.

Ruud maintains KiXtart quite actively, and if a feature is popular enough it may well get into a new release.

Top
#35636 - 2003-01-24 10:46 AM Re: Continue and Break in FOR-NEXT loops
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Well,

this feature request is now on the list for a long time ... since 4.11 IIRC ???

Maybe you should repost your request in SUGGESTIONS forum (Or a Moderator could move the topic to it) in order to get Ruuds attention ...

J.
_________________________



Top
#35637 - 2003-01-24 03:43 PM Re: Continue and Break in FOR-NEXT loops
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Proper coding of loops don't require these features most of the time. One just has to set up the loop correctly insetad of trying to use shortcuts.
_________________________
There are two types of vessels, submarines and targets.

Top
#35638 - 2003-01-24 04:08 PM Re: Continue and Break in FOR-NEXT loops
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
I'm with you Jens!

I think time would be better spent adding other features that would be more useful.

Such as Exp(), ReplaceStr(), RepeatStr(), any-to-any base numerical conversion and the declaring of constants to name but a few!

Lee

Top
#35639 - 2003-01-24 04:18 PM Re: Continue and Break in FOR-NEXT loops
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
hey ... lookie here
_________________________



Top
#35640 - 2003-01-24 04:19 PM Re: Continue and Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

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

You are implying that use of break and continue in the context of loops is improper coding.

In fact IMO it is quite the opposite.

Using break to exit a loop is both elegant and more "correct" than kludging the exit by artificially forcing the loop condition.

For example, exit from a "For Each..." loop is ugly without a break.

"continue" too is an excellent tool in limiting the scope of processing within a loop in an explicit and inexpensive manner.

These aren't merely shortcuts. They are useful directives which make code more readable and less ambiguous, and will improve performance over the alternatives.

Of course you can always code around the absence of these directives and we do, but in some cases scripts would be neater, shorter, faster and less inscrutable if we didn't have to.

I'll stop now, I'm beginning to repeat myself.

Top
#35641 - 2003-01-24 04:25 PM Re: Continue and Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
rich, I still wonder who uses for-each-looping if they still don't want to go for each.

there is no need for breaking that up.
_________________________
!

download KiXnet

Top
#35642 - 2003-01-24 04:30 PM Re: Continue and Break in FOR-NEXT loops
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
for each until whatever next?
for each and every until done 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
#35643 - 2003-01-24 04:57 PM Re: Continue and Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Hah, calling my bluff eh?

The most likely reason to want to break out of a "For Each" loop is because you were looking for something, and you've found it.

As a trivial example, say you know that your script was started as "kix32.exe myscript.kix" and you wanted to know where the kix32.exe executable was?

The way to do it is to check the current directory, and then each directory in your %PATH% environment variable until you find it. Once you've found it you don't need (or want) to process the rest of the directories in your path.

Similarly you may be looking for the key in an ini file which has a specific value, or in a list returned from a LDAP query, or perhaps you are totalling values in a list and have exceeded a maximum so there is no point in further processing.

Those are just off the top of my head, I'm sure you can easily think of more appropriate examples.

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

Registered: 2001-06-05
Posts: 22346
Loc: OK
I thought the while loop can be used for these [Wink]
_________________________
!

download KiXnet

Top
#35645 - 2003-01-24 05:17 PM Re: Continue and Break in FOR-NEXT loops
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jooel,
Show me how you would do it with WHILE.

for each $element in $array
 while ?
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
#35646 - 2003-01-24 06:09 PM Re: Continue and Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, ok.
I thought there is now newbies reading this.

while $check and $counter<$max

once you have the condition, you make hit $check.
this is the ultimate-correct-way
_________________________
!

download KiXnet

Top
#35647 - 2003-01-24 10:09 PM Re: Continue and Break in FOR-NEXT loops
Stevie Offline
Starting to like KiXtart
*****

Registered: 2002-01-09
Posts: 199
There are always situations that will require a break from a loop.

The best example I can think of is a deeply nested loop:

code:
For Each...in...
For Each...in...
While...
blah blah blah...

Loop
Next
Next

I'm sure we've all seen code like this or have coded ourselves into these situations. Sometimes nesting these statements is the quickest/best way to do something. In those cases when you're buried way down there, breaking out of the entire loop is the most elegant solution.

[ 24. January 2003, 22:11: Message edited by: Steve B ]
_________________________
Stevie

Top
#35648 - 2003-01-24 10:26 PM Re: Continue and Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
breaking is never elegant.

it just means that you are too lame or lazy of coming out properly.
_________________________
!

download KiXnet

Top
#35649 - 2003-01-27 09:55 AM Re: Continue and Break in FOR-NEXT loops
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
quote:
it just means that you are too lame or lazy of coming out properly.
That's a pretty strong statement. Are you sure that people who code using "break" are lame and lazy?

We have had both "break" and "continue" in 'C' for as long as I can remember, and I consider myself and fellow 'C' coders to be diligent and professional.

"Break" and "continue" are language constructs which simplify code and make it execute faster. They formalise and standardise process control which makes the understanding and maintenence of the code simpler.

We don't need FOR/NEXT, WHILE/LOOP, or DO/UNTIL control structures - the processing can be emulated perfectly well with a couple of variables and GOTO, but who wants to write kludgy ugly code when there is a better alternative?

Top
#35650 - 2003-01-27 10:02 AM Re: Continue and Break in FOR-NEXT loops
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it was kinda too strongly said. can admit.

anyway, like I said, it's never a must to have such thing...
all though it can make life easier for some.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.075 seconds in which 0.033 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