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
[Implemented] Premature Exits
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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

-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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?
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
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by vanleth.
But thats even more worse coding style
Code: Select all
repeat
if ...
Goto breakit
endif
until ...
breakit:
...
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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.
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.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm