[Implemented] Exit command

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] Exit command

Post by BackupUser »

Restored from previous forum. Originally posted by Amiga5k.

This can come in handy in certain situations. Normally, in other Basics, this will exit you from the inner-most 'current' loop. Like:
Repeat
a = a + 1
Repeat
b = b + 1
IF b = 100 then Exit ; Will jump out of this R/F loop
Forever
Until a = 100

An option that would be even more interesting, would be the ability to specify how many loops to jump. For example, in the same code above, 'Exit' could be changed to 'Exit 2' to jump to the statement immediately AFTER 'Until a = 100'. The example is pretty silly, but you get the idea. :)

(Implemented as 'Break')

Russell


***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by DemonHell.
Originally posted by Amiga5k

This can come in handy in certain situations. Normally, in other Basics, this will exit you from the inner-most 'current' loop. Like:

An option that would be even more interesting, would be the ability to specify how many loops to jump. For example, in the same code above, 'Exit' could be changed to 'Exit 2' to jump to the statement immediately AFTER 'Until a = 100'. The example is pretty silly, but you get the idea. :)
Err, why??
Thats what the Until command means ( ie, Repeat this code Until this condition is met)...why not just OR several conditions in one Until command.
ie.
Repeat

Until (a=100)or(b=50)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Amiga5k.

One reason is that you may have multitudes of different conditions that could/should end a loop and using 'until' with 10 or 15 condition checks can really make for a long line of code. But with Exit (which is available in many other languages, and Basics) you can split it up over several lines. And sometimes I may want to leave the loop somewhere in the middle, and not wait until I get to the bottom of the loop ('Until') or do it at the very beginning ('While'). Also, I'm lazy... :)

"Exit n" could come in handy to break out of a set of very nested loops easily. Probably not something that a seasoned C++ prgrammer would use, but hey, we still have "Goto" which is pretty much unnecessary (except for speed optimization).

It's not something I would use as much as For/next or if/endif, but in languages that I've used that do support such a thing (Powerbasic has 'Exit For' to leave a For/Next loop, for example), I find it very handy on occasion.

Russell

***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by gnozal.

I think EXIT (DO/FOR/...) is more 'clean' than [Repeat / Quit = 1 / Until Quit = 1].
Besides, it's not such an exotic request. You can find these commands in Quickbasic, Powerbasic, ... almost every basic dialect.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Amiga5k.

I agree. On the priority list, though, I suppose I'd have to give this a 2 out of 10. To me, 10/10 would be user guide and syntax/code stabilization (not to be confused with executable stability).

Scroll bars are very common in gui apps, so I would put that up near the top as well. But if it's true that Fred is doing a complete rewrite of the compiler for version 4, then I'm sure he has other fish to fry first. :)

Still, exit would be nice to have.

Russell

***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
Post Reply