SRL Archive - Help and Support

Labels


Sin

2012-03-12 14:42:56

Any idea how to call them?

Label;
if findthing then
begin
dostuff;
end else
if dothis then
Label;

Gu3st...

2012-03-12 15:01:34

goto LabelName;

masterBB

2012-03-12 15:09:24

This is a loop. Similar to repeat…until(x);


Label start;
writeln('loop');
if(not(x)) then
goto start;

Sin

2012-03-12 15:10:04

From: masterBB
This is a loop. Similar to repeat…until(x);


Label start;
writeln('loop');
if(not(x)) then
goto start;


From: Zyt3x
goto LabelName;




Thanks both of you! :)

Justin

2012-03-13 04:04:43

Thanks both, never knew how labels worked!

masterBB

2012-03-17 10:18:42

I explained it a bit wrong. Here is a better example. Note that if you use lape that labels are faster. If you use pascalscript the for loop is faster.

program new;

{$Define lape}

procedure Test1;
label
start;
var
i,b:Integer;
begin
i := 0;
start:
inc(i);
inc(b);
if i < 10000000 then
goto start;
end;

procedure Test2;
var
i,b:Integer;
begin
for i := 0 to 10000000 do
inc(b);
end;

var
timer:Integer;

begin
{$IFDEF lape}
timer := GetTickCount;
Test1;
writeln(GetTickCount - timer);

timer := GetTickCount;
Test2;
writeln(GetTickCount - timer);
{$ELSE}
timer := GetSystemTime;
Test1;
writeln(GetSystemTime - timer);

timer := GetSystemTime;
Test2;
writeln(GetSystemTime - timer);
{$ENDIF}
end.

Jagex_Fagex

2012-03-17 15:33:21

How interesting… I didn't even know these existed, and they could be exactly what i was looking for earlier, then again, a normal loop may suffice. Can anyone tell me the benefits of these over a standard for loop?

masterBB

2012-03-17 16:09:17

None. I posted my benchmarks here: http://villavu.com/forum/showthread.php?t=68613

As you see they may differ for everyone.

Home

2012-03-17 16:13:50

Don't use Labels.

If you need to use Labels. Then re-do your function :)

I know that this might sound like a spam, but it's not it. I once used labels, way too often, then I decided to re-write whole function and result was much better!

~Home

nielsie95

2012-03-17 16:16:21

http://www.delphibasics.co.uk/RTL.asp?Name=Goto
So it's not a good idea to use for loops, but it could be an option to jump out of some heavy nesting.

http://xkcd.com/292/

Naum

2012-03-17 16:18:32

From: Home
Don't use Labels.

If you need to use Labels. Then re-do your function :)

I know that this might sound like a spam, but it's not it. I used Labels too once way too often, then I decided to re-write whole function and result was much better!

~Home


I don't agree, I haven't really noted any drawbacks of using labels, they're immensely helpful, provided you follow logic to avoid infinite loops. Which, you should know how to avoid or you wouldn't be needing to use them.

masterBB

2012-03-17 16:21:14

Have to post this one: http://xkcd.com/292/

But yeah, if you are using high level languages as pascalscript or even c++, you should avoid them. It becomes a bit messy when you use them.

edit:
nielsie als posted it. ninja'd