Page 2 of 2

Re: Break to a specific statement label

Posted: Mon Feb 20, 2012 7:04 pm
by ts-soft
Image
- without words -

Re: Break to a specific statement label

Posted: Mon Feb 20, 2012 7:14 pm
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)

Re: Break to a specific statement label

Posted: Sat Feb 25, 2012 4:50 pm
by luis
fsw wrote:First:
Don't want to start a discussion about GOTO is good/bad.
Why this preamble ?

Re: Break to a specific statement label

Posted: Sat Feb 25, 2012 9:13 pm
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.