SRL Archive - OSR Help

Exit;


Dgby714

2010-04-21 12:50:03

Hmm is there a way to Exit from the current procedure and the procedure that called it? without making a function and a if stuff then exit;

kinda like


procedure OtherStuff;
begin
WriteLn('OtherStuff Start...');
//Some exit command here.....
WriteLn('OtherStuff End...');
end;

procedure Stuff;
begin
WriteLn('Stuff Start...');
OtherStuff;
WriteLn('Stuff End...');
end;

begin
WriteLn('Start...');
Stuff;
WriteLn('End...');
end.
would output
Start...
Stuff Start...
OtherStuff Start...
End...

mastaraymond

2010-04-21 12:55:36

From: Dgby714
Hmm is there a way to Exit from the current procedure and the procedure that called it? without making a function and a if stuff then exit;

kinda like


procedure OtherStuff;
begin
WriteLn('OtherStuff Start...');
//Some exit command here.....
WriteLn('OtherStuff End...');
end;

procedure Stuff;
begin
WriteLn('Stuff Start...');
OtherStuff;
WriteLn('Stuff End...');
end;

begin
WriteLn('Start...');
Stuff;
WriteLn('End...');
end.
would output
Start...
Stuff Start...
OtherStuff Start...
End...

No… Make the procedure a function with a boolean as result, to indicate whether it succeeded or not.

Sir R. M8gic1an

2010-04-21 13:09:15


function OtherStuff: boolean;
begin
Result := false;
WriteLn('OtherStuff Start...');

if not Result then exit;
WriteLn('OtherStuff End...');
end;

procedure Stuff;
begin
WriteLn('Stuff Start...');
if not OtherStuff then exit;
WriteLn('Stuff End...');
end;

begin
WriteLn('Start...');
Stuff;
WriteLn('End...');
end.

~RM

Nava2

2010-04-21 13:34:59

You could use goto and labels, but that is *highly* unadvised.

Its crappy style and in general just not recommended.

It does allow you do move through your code directly.

mastaraymond

2010-04-21 13:38:55

From: Nava2
You could use goto and labels, but that is *highly* unadvised.

Its crappy style and in general just not recommended.

It does allow you do move through your code directly.

Labels can't go outside the method:confused::confused::confused:

Nava2

2010-04-21 13:43:06

Make them global?

Dgby714

2010-04-21 13:45:20

From: mastaraymond
…

From: Rasta Magician
…

I said without turning it into a function….


From: Nava2
You could use goto and labels, but that is *highly* unadvised.

Its crappy style and in general just not recommended.

It does allow you do move through your code directly.

Yeah ive looked into labels i dont like em though…

From: mastaraymond
Labels can't go outside the method:confused::confused::confused:

You cant make global labels? (like global variables)

mastaraymond

2010-04-21 13:47:40

That's just impossible, methods have their own stack for variables etc..

@Dgby714; what you are trying to accomplish is silly, the only way to 'exit' the parent function would be to throw an exception and catch that later on, however that's is really radical and should be avoided by good programming.

NCDS

2010-04-21 16:27:26

From: Nava2
You could use goto and labels, but that is *highly* unadvised.

Its crappy style and in general just not recommended.

It does allow you do move through your code directly.


Sorry for offtopic and feel free to just MSN/PM back but what is so crappy about the style of labels?

I can see why you may not recommend them for organizational purposes, but I find them quite useful in some cases.

mastaraymond

2010-04-21 16:53:43

From: NCDS
Sorry for offtopic and feel free to just MSN/PM back but what is so crappy about the style of labels?

I can see why you may not recommend them for organizational purposes, but I find them quite useful in some cases.

Labels in Pascalscript seriously serve no purpose as they cannot jump out of loops.. But yeah, a lazy coder is lazy.

NCDS

2010-04-21 16:59:29

From: mastaraymond
Labels in Pascalscript seriously serve no purpose as they cannot jump out of loops..

So use a boolean?
From: mastaraymond

But yeah, a lazy coder is lazy.

So the use of labels makes me a lazy coder? I would think of it more as resourceful.

Killerdou

2010-04-21 18:05:15


function A : boolean;
begin
blablabla;
if something then exit;
blablabla;
result := true;

end;

procedure B;
begin
if not A then exit;
end;

Not exactly what you want, but maybe closer to it?
Anyways, what exactly are you trying to do with this?
If it's a recursive algorithm I will…..