Autor Tema: break(int n) and continue(int n)  (Leído 10210 veces)

Rincewind

  • Newbie
  • *
  • Mensajes: 10
  • Karma: 0
    • Strictly Rational
break(int n) and continue(int n)
« en: Octubre 14, 2007, 12:40:22 am »
Hello everyone. :)

First of all I am glad Juan didn't make this forum Spanish-only like the fenix.divsite.net forum, because that would totally fail to adress the international community. English is after all the default internet language.

I have a suggestion that I've been thinking of for some time now: A break(int <amount of loops>) and continue(int <amount of loops>) would be fantastic to have. Basically what they do is breaking or continuing multiple nested loops. I've missed this while programming and had to use variables to pass a signal between multiple planes of nested loops instead, which really isn't handy.

Hopefully you'll implement it, thanks in advance.
Getting things done is vital.

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12962
  • Karma: 378
Re: break(int n) and continue(int n)
« Respuesta #1 en: Octubre 14, 2007, 01:50:34 am »
Hi! Wellcome!

I don´t understand, what can be the use for this sentences...

break and continue, not only for loop use... the condition should not be in break or continue, but in the while, for, etc ...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Re: break(int n) and continue(int n)
« Respuesta #2 en: Octubre 14, 2007, 02:18:41 am »
He means:
[code language="bennu"]
while( cond1 )
    while( cond2 )
        if( cond3 )
            cond1 = cond2 = false;
        end
    end
end
[/code]
...becomes...
[code language="bennu"]
while( cond1 )
    while( cond2 )
        if( cond3 )
            break( 2 );
        end
    end
end
[/code]
...I think.
-- Sandman

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12962
  • Karma: 378
Re: break(int n) and continue(int n)
« Respuesta #3 en: Octubre 14, 2007, 02:47:14 am »
Too complex...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Rincewind

  • Newbie
  • *
  • Mensajes: 10
  • Karma: 0
    • Strictly Rational
Re: break(int n) and continue(int n)
« Respuesta #4 en: Octubre 14, 2007, 01:13:53 pm »
Cita de: Juan
I don´t understand, what can be the use for this sentences...

break and continue, not only for loop use... the condition should not be in break or continue, but in the while, for, etc ...

The use of this is that you for example can break multiple loops, which can't be done by setting the conditions of two loops to true simply because the current loop cycles (the cycle of the inner and outer loop, in the example below) will still be finished then, that's why these loop-manipulative statements are handy in the first place.

[code language="bennu"]
loop
    loop
        if (...)
            My_variable=1;
            break;                       
        end               
    end
       
    if (My_variable)
        break;
    end
               
    //<more code>
end
[/code]

would become:

[code language="bennu"]
loop
    loop
        if (...)
            break(2);                       
        end               
    end
             
    //<more code>
end
[/code]

Notice how <more code> isn't executed in the example above. By simply setting conditions of loops to true (for example in For or While loops) instead of using break, <more code> will be executed which wasn't what we wanted!
« última modificación: Octubre 14, 2007, 02:57:50 pm por Rincewind »
Getting things done is vital.

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12962
  • Karma: 378
Re: break(int n) and continue(int n)
« Respuesta #5 en: Octubre 14, 2007, 04:19:09 pm »
Is very easy put bugs in your code with this method, for example, including a new loop in huge loop...
Maybe the best options is add a GOTO statement...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12962
  • Karma: 378
Re: break(int n) and continue(int n)
« Respuesta #6 en: Octubre 14, 2007, 04:20:56 pm »
for example:

[code language="bennu"]
loop
    loop
        if (...)
            goto my_exit;                         
        end                 
    end
 
    //<more code>
end
:my_exit
//<more code>
[/code]
« última modificación: Octubre 14, 2007, 04:22:35 pm por SplinterGU »
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Rincewind

  • Newbie
  • *
  • Mensajes: 10
  • Karma: 0
    • Strictly Rational
Re: break(int n) and continue(int n)
« Respuesta #7 en: Octubre 14, 2007, 05:58:35 pm »
Citar
Is very easy put bugs in your code with this method, for example, including a new loop in huge loop...
Maybe the best options is add a GOTO statement...

Well, the idea of structured programming using structured statements like break(int n) is that it would be less easy to slip in a bug than using GOTO's everywhere.  :-\

But I guess if a break(int n) is too complex to add then GOTO is indeed better than having an extra variable and an extra if statement. I didn't even realize a GOTO existed in Bennu/Fenix.
Getting things done is vital.

HaCkZJuaNN

  • Full Member
  • ***
  • Mensajes: 179
  • Karma: 5
Re: break(int n) and continue(int n)
« Respuesta #8 en: Octubre 14, 2007, 07:15:28 pm »
I think it doesn't exist now, but splinter says maybe it would be better to add it than to add break(int n).

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12962
  • Karma: 378
Re: break(int n) and continue(int n)
« Respuesta #9 en: Octubre 14, 2007, 07:41:43 pm »
GOTO never is buggy... is exact...

I never heard of "break(n)", only "break"...

GOTO don't exist yet... but could exist in the future...


Download Lastest BennuGD Release: http://www.bennugd.org/node/2

izubiaurre

  • Administrator
  • *****
  • Mensajes: 426
  • Karma: 23
    • ::IDE for BennuGD::
Re: break(int n) and continue(int n)
« Respuesta #10 en: Octubre 14, 2007, 07:48:25 pm »
I never heard of "break(n)", only "break"...

I haven't heard before too.

Rincewind

  • Newbie
  • *
  • Mensajes: 10
  • Karma: 0
    • Strictly Rational
Re: break(int n) and continue(int n)
« Respuesta #11 en: Octubre 14, 2007, 08:37:30 pm »
Cita de: HaCkZJuaNN
I think it doesn't exist now, but splinter says maybe it would be better to add it than to add break(int n).

Ah right.

Cita de: SplinterGUI
GOTO never is buggy... is exact...

I didn't mean GOTO itself is buggy, but that using GOTOs as opposed to a structured statement will allow the programmer to get lost in his own code easier, and thus the programmer could introduce bugs easier. Of course it is up to the programmer what to use, but personally I'd prefer a break(n) statement. Optionally of course GOTO would also be an addition, since there isn't one yet.

Citar
I never heard of "break(n)", only "break"...

Break(n) already exists in some newer languages, for example PHP.
Getting things done is vital.

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Re: break(int n) and continue(int n)
« Respuesta #12 en: Octubre 14, 2007, 09:06:47 pm »
Half on topic: I like GOTO and labels, good plan.
-- Sandman

FreeYourMind

  • Hero Member
  • *****
  • Mensajes: 5727
  • Karma: 129
    • GECA soft
Re: break(int n) and continue(int n)
« Respuesta #13 en: Julio 22, 2010, 11:28:44 pm »
for example:

[code language="bennu"]
loop
    loop
        if (...)
            goto my_exit;                         
        end                 
    end
 
    //<more code>
end
:my_exit
//<more code>
[/code]

I have an error:

Código: [Seleccionar]
IF (_key(_space, _key_down))
GOTO etiqueta;
END

IF (_key(_space, _key_up))
    BREAK;
END

:etiqueta

....


Error: Unknown identifier: Etiqueta.

What's wrong ?

SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12962
  • Karma: 378
Re: break(int n) and continue(int n)
« Respuesta #14 en: Julio 23, 2010, 06:20:40 am »
tal vez "etiqueta:" ?
Download Lastest BennuGD Release: http://www.bennugd.org/node/2