Bennu Game Development

English Forums => Suggestions => Mensaje iniciado por: Rincewind en Octubre 14, 2007, 12:40:22 am

Título: break(int n) and continue(int n)
Publicado por: Rincewind 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.
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU 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 ...
Título: Re: break(int n) and continue(int n)
Publicado por: Sandman 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.
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Octubre 14, 2007, 02:47:14 am
Too complex...
Título: Re: break(int n) and continue(int n)
Publicado por: Rincewind 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!
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU 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...
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU 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]
Título: Re: break(int n) and continue(int n)
Publicado por: Rincewind 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 (http://en.wikipedia.org/wiki/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.
Título: Re: break(int n) and continue(int n)
Publicado por: HaCkZJuaNN 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).
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU 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...


Título: Re: break(int n) and continue(int n)
Publicado por: izubiaurre en Octubre 14, 2007, 07:48:25 pm
I never heard of "break(n)", only "break"...

I haven't heard before too.
Título: Re: break(int n) and continue(int n)
Publicado por: Rincewind 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 (http://nl3.php.net/manual/en/control-structures.break.php).
Título: Re: break(int n) and continue(int n)
Publicado por: Sandman en Octubre 14, 2007, 09:06:47 pm
Half on topic: I like GOTO and labels, good plan.
Título: Re: break(int n) and continue(int n)
Publicado por: FreeYourMind 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 ?
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Julio 23, 2010, 06:20:40 am
tal vez "etiqueta:" ?
Título: Re: break(int n) and continue(int n)
Publicado por: FreeYourMind en Julio 23, 2010, 07:14:29 am
What means 'tal vez' ?
Hhehheheh, it's a joke ;)

etiqueta: it's the same, don't work.
An example please  :D
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Julio 23, 2010, 07:32:14 am
works...

Código: [Seleccionar]
import "mod_say";

begin

    say ( "Init" );

    if ( 1 )
        goto label;
    end

    say ( "I don't must displayed!" );

    return;

label:
    say ( "I'm label!" );

end

if you had made an example you had solved it!
Título: Re: break(int n) and continue(int n)
Publicado por: FreeYourMind en Julio 23, 2010, 08:14:14 am
Don't work, don't recognize the label.

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

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

label: say("lol");

 >:( Some import, declaration is missing ?
Título: Re: break(int n) and continue(int n)
Publicado por: FreeYourMind en Julio 23, 2010, 08:26:20 am
Your example works!!!!


Here is my example, don't work:

Código: [Seleccionar]
import "mod_say";
import "mod_key";

begin

    my_process();

LOOP

if (key(_esc))
    exit("");
END


FRAME;
END

end

PROCESS my_process()
BEGIN

say ( "Init" );

LOOP

  if (key(_space))
  GOTO label;
  END

  label: say("lol");

FRAME;
END

END

Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Julio 23, 2010, 12:25:10 pm
label must be aligned to margin left! :P
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Julio 23, 2010, 12:30:53 pm
works!

Código: [Seleccionar]
import "mod_video";
import "mod_say";
import "mod_key";
import "mod_proc";

begin

    my_process();

LOOP

if (key(_esc))
    exit("");
END


FRAME;
END

end

PROCESS my_process()
BEGIN

say ( "Init" );

LOOP

  if (key(_space))
  GOTO label;
  END

    frame;
continue;
label: say("lol");

FRAME;
END

END
Título: Re: break(int n) and continue(int n)
Publicado por: FreeYourMind en Julio 23, 2010, 12:52:35 pm
Interesting error origin... It's posible to fix and ignore tabulation when using goto's ?
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Julio 23, 2010, 12:55:55 pm
It isn't an error... It's is intentional... must be...
Título: Re: break(int n) and continue(int n)
Publicado por: SplinterGU en Julio 23, 2010, 01:01:50 pm
In other way, in this thread we talk only about a proposal GOTO syntax, the final GOTO syntax thread is other... I'll close this thread.