Page 1 of 1 1
Topic Options
#80034 - 2001-04-25 09:35 PM We desperately need an ExitFor statement
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
We're going to "need" an ExitFor statement sooner or later !

Just thought I'd just mention this sooner, than later!

Anyone have any "clean" workarounds in the meantime (apart from gotos). Artificially bumping-up the index inside the for-next works:

code:

break on

for $i=1 to 10

?"i=$i"
if $i=5
$i=11
endif

next

exit



Shawn.

[This message has been edited by Shawn (edited 25 April 2001).]

Top
#80035 - 2001-04-25 09:59 PM Re: We desperately need an ExitFor statement
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
This is the only workaround I can thing of too. I used something similar in my pre-FOR...NEXT days:

code:

$i=0
do
"i = $i" ?
if $i=5 $i=9 endif
$i=$i+1
until $i=10


I think that EXIT and QUIT should be refined so that EXIT will exit from any FOR...NEXT, IF...ENDIF, DO...UNTIL and WHILE...LOOP loop. And QUIT should immediately quit the current script. I have found that sometimes I have to do QUIT QUIT to get out then and there.

cj

Top
#80036 - 2001-04-25 10:10 PM Re: We desperately need an ExitFor statement
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ceej:

Right on. I'm thinking that even though this workaround works, things aren't quite as straight-forward when using the FOR-EACH-IN-NEXT statement. Because one is dealing with arrays and OLE collections, how would one "fake-out" the last object + 1 ? By poking the object index internally ?

quit quit eh ? Sometimes I have to say this to my wife and children when the first quit doesn't work

Shawn.

p.s.

Have you written a game for k2k yet ?

Shawn..

Top
#80037 - 2001-04-25 10:21 PM Re: We desperately need an ExitFor statement
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
You can comment the OLE lines in KiXAdventure and run that

I am still working on V2.0 of that game but it won't have k2k only code. It does have a generated map that goes in all directions forever(or KiX's version of such) and if you go up and up and then down and down the map is the same.

I have been playing with MSAgents and have a k2k version if you like. I am going to make an Eliza program with MSAgents next. Have to quickly do some work related coding so that no-one notices that I am getting nothing done

cj

Top
#80038 - 2001-04-27 06:25 PM Re: We desperately need an ExitFor statement
Anonymous
Unregistered


Thanks, I look into EXITFOR.

For now, GOTO can also be used to leave a FOR-NEXT loop.

Ruud

Top
#80039 - 2001-04-30 01:39 PM Re: We desperately need an ExitFor statement
Anonymous
Unregistered


Ruud,
Is there a risk of a stack overflow, or similar problem, when using GOTO to exit the loop?

Top
#80040 - 2001-05-01 03:39 PM Re: We desperately need an ExitFor statement
Anonymous
Unregistered


I have used 2 commands in other languages called LEAVE and ITERATE that operate in all loop structures (eg DO UNTIL, WHILE LOOP, FOR NEXT and FOR EACH NEXT)
LEAVE exits the innermost executing loop,
ITERATE goes to the end of the loop (ie the UNTIL, LOOP, NEXT command).

Top
#80041 - 2001-05-01 05:59 PM Re: We desperately need an ExitFor statement
Anonymous
Unregistered


On the question regarding the risk of stack over-/underflow as a result of GOTO'ing out of a loop: no, this is handled by the KiXtart interpreter.

Regards,

Ruud

Top
#80042 - 2006-04-07 09:56 AM Re: We desperately need an ExitFor statement
Biro Offline
Fresh Scripter

Registered: 2006-04-07
Posts: 7
Loc: NSW, Australia
I so agree with the sentiment of this request.
(hope ive posted correctly)

Perhaps my logic was floored but I have found that
using a GOTO to exit a loop within a nested loop, it
has troubles from having a :Label within that loop.
Either way is messy compared to a proper exit command.

I think EXIT should behave differently 'except' that this
could really mess with backward compatibility for anyone
maintaining scripts written in the past which would be
expecting EXIT to exit.

So something else to do it would make more sense?

Top
#80043 - 2006-04-07 10:04 AM Re: We desperately need an ExitFor statement
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Biro - welcome to the board.

Not sure if you noticed or not but this was last posted to on: Tue May 01 2001

KiXtart has evolved quite a bit since those days as well as the skill of many scripters around here.

In general the use of GOTO and GOSUB are pretty much old hat and not recommended for modern scripting with KiXtart.

If you have a specific request or task you're having difficulty coding please post a new topic in either STARTERS or GENERAL and we will try to assist you with the task.
 

Top
#80044 - 2006-04-07 03:38 PM Re: We desperately need an ExitFor statement
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Biro,
Suggestions that have not been implemented or otherwise deprecated cannot go out of date.

Thank you for your support
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.176 seconds in which 0.14 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