Page 1 of 1
[Implemented] Premature Exits
Posted: Sun Jan 19, 2003 11:29 pm
by BackupUser
Restored from previous forum. Originally posted by geoff.
There are 2 commands I would like to see in PureBasic
1) A command that can be placed anywhere within a procedure
that causes immediate return from the procedure.
ie like RETURN in C, or EXPROC in some Basics
This is useful for error exits from a procedure and can
simplify or remove nested IF--ENDIF structures and extra
condition variables in subsequent code lines.
2) A command that can be placed anywhere within a FOR--NEXT
loop or WHILE--WEND loop that jumps to the end of the loop.
ie like BREAK in C, EXIT and EXIT_IF in some Basics
This is useful to simplify or eliminate IF--ENDIF
structures within a loop.
Who else misses these 2 useful commands?
Geoff
Posted: Sun Jan 19, 2003 11:36 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
You can use 'ProcedureReturn' to jump out of a procedure, just be carefull if you try to jump out of a Select:Case structure -it doesn't work properly yet.
Posted: Sun Jan 19, 2003 11:41 pm
by BackupUser
Restored from previous forum. Originally posted by vanleth.
Had to admit I would use those features / commands if they existed.
But they would also make my code more messy for me in the long run.
Without them I'm kinda forced to write cleaner code and not just do stragihtforward Hack and Slash programming.
I would use them , but am better without them

Posted: Sun Jan 19, 2003 11:47 pm
by BackupUser
Restored from previous forum. Originally posted by geoff.
Thanks Pupil.
From the help file, I thought that ProcedureReturn just set the return
result. It doesn't say that it also causes immediate return.
OK one down.
Any one any ideas on the BREAK loop exit?
Posted: Mon Jan 20, 2003 12:32 am
by BackupUser
Restored from previous forum. Originally posted by geoff.
I don't like the "Hack and Slash" comment Vanleth.
BREAK is not nasty like GOTO.
Isn't the first of these 3 routines clearest?
Maybe it's a personal thing?
Code: Select all
;find 1st string with weekend day
for i=1 to 100
if FindString(a$(i),"Saturday",1)
BREAK; found
elseif FindString(a$(i),"Sunday",1)
BREAK; found
endif
next i
found=0
For i=1 to 100
if FindString(a$(i),"Saturday",1)
found=1
else if FindString(a$(i),"Sunday",1)
found=1
endif
if found
i=100;force loop exit
endif
next i
found=0
i=0
while not found
i=i+1
if FindString(a$(i),"Saturday",1)
found=1
else if FindString(a$(i),"Sunday",1)
found=1
endif
wend
Posted: Mon Jan 20, 2003 12:32 am
by BackupUser
Restored from previous forum. Originally posted by vanleth.
Code: Select all
repeat
if ...
Goto breakit
endif
until ...
breakit:
...
But thats even more worse coding style
Posted: Mon Jan 20, 2003 12:40 am
by BackupUser
Restored from previous forum. Originally posted by vanleth.
To Geoff:
Well I admit the first one is most clear. Think what I tried to say was that I try to avoid using dirty loop breaks for the app's main loops. But when it comes to small routine looping, I can see your point.
Then clearly the first one is the most easy to read.
Posted: Mon Jan 20, 2003 9:26 am
by BackupUser
Restored from previous forum. Originally posted by fred.
Yes, it's planned (Break/Continue C like operands).
Fred - AlphaSND