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.
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 ...
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.
Too complex...
Quote from: JuanI 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!
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...
for example:
[code language="bennu"]
loop
loop
if (...)
goto my_exit;
end
end
//<more code>
end
:my_exit
//<more code>
[/code]
QuoteIs 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.
I think it doesn't exist now, but splinter says maybe it would be better to add it than to add break(int n).
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...
Quote from: SplinterGU on October 14, 2007, 07:41:43 PM
I never heard of "break(n)", only "break"...
I haven't heard before too.
Quote from: HaCkZJuaNNI 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.
Quote from: SplinterGUIGOTO 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.
QuoteI 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).
Half on topic: I like GOTO and labels, good plan.
Quote from: SplinterGU on October 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]
I have an error:
IF (_key(_space, _key_down))
GOTO etiqueta;
END
IF (_key(_space, _key_up))
BREAK;
END
:etiqueta
....
Error: Unknown identifier: Etiqueta.
What's wrong ?
tal vez "etiqueta:" ?
What means 'tal vez' ?
Hhehheheh, it's a joke ;)
etiqueta: it's the same, don't work.
An example please :D
works...
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!
Don't work, don't recognize the label.
IF (_key(_space, _key_down))
GOTO label;
END
IF (_key(_space, _key_up))
BREAK;
END
label: say("lol");
>:( Some import, declaration is missing ?
Your example works!!!!
Here is my example, don't work:
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
label must be aligned to margin left! :P
works!
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
Interesting error origin... It's posible to fix and ignore tabulation when using goto's ?
It isn't an error... It's is intentional... must be...
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.