Break to a specific statement label

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Break to a specific statement label

Post by ts-soft »

Image
- without words -
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Break to a specific statement label

Post by fsw »

First:
Don't want to start a discussion about GOTO is good/bad.


Second:
Some other languages have labeled statements.

A labeled for loop in PB could look like this:

Code: Select all

Procedure myProc(x)
    Found: For i=1 To 50
        If i=x
            Break Found
        EndIf
        ...
    Next
    ....
EndProcedure
This also helps a lot when there are statements inside statements and all are ready to accept BREAK.
Using labeled breaks you can jump out of several statements at once.

Granted you can do the same with GOTO, but IMHO the initial request is still valid and a good one.

@ts-soft
I like it 8)
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Break to a specific statement label

Post by luis »

fsw wrote:First:
Don't want to start a discussion about GOTO is good/bad.
Why this preamble ?
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Break to a specific statement label

Post by charvista »

GOTO is excellent, no doubt, because it does the job it was designed for.
Only the programmer can possibly be bad, when s/he makes spaghetti code. However, I like spaghetti very much. :P
It is that simple. No discussion is necessary. You use it or you don't.

I however regret that the GOTO's companion GOSUB cannot be used within procedures. Sometimes, it would be very handy.
OK, we have procedures, but GOSUB has the advantage to use all variables, while you need to pass them as parameters in procedures.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Post Reply