SRL Archive - OSR Help

Simple question


Shatterhand

2012-04-04 14:15:37

if (function_A or function_B) then
DoSomething;
NextCommand;
If function_A returns with True, will function_B be skipped or not?

Sex

2012-04-04 14:45:41

This is called short circuit evaluation. All conditions will be evaluated before continuing if you use the code you provided.

You could also test this yourself like this:

function One : boolean;
begin
result := false;
Writeln('One ran');
end;

function Two : boolean;
begin
result := true;
Writeln('Two ran');
end;

begin
if One or Two then
Writeln('Expression is true');
Writeln('Next');
end.
Edit: You should use a more descriptive title next time as I almost skipped it :).

You can do this if you want short circuit evaluation:
function One : boolean;
begin
result := false;
Writeln('One ran');
end;

function Two : boolean;
begin
result := true;
Writeln('Two ran');
end;

begin
if One and (Two or One) then
Writeln('Expression is true');
Writeln('Next');
end.

Shatterhand

2012-04-04 15:20:38

Thanks for the answer, but you my point was to have the first function returned with True so second function no need to be compiled. So second function is like a second method of doing the job. Like this:
function One : boolean;
begin
result := True;
Writeln('One ran');
end;
function Two : boolean;
begin
result := False;
Writeln('Two ran');
end;
begin
if One or Two then
Writeln('Expression is true');
Writeln('Next');
end.

Output is:
One ran
Expression is true
Next

EDIT: I dont really understand the usage of ur second code (short circuit)… if One is true, then the line is true, if Two is true, One needs to be true too….What is this for?

Sex

2012-04-04 15:50:54

Ah, in that case.

function One : boolean;
begin
result := true;
Writeln('One ran');
end;

function Two : boolean;
begin
result := false;
Writeln('Two ran');
end;

begin
if not One and (Two or One) then
Writeln('Expression is true');
Writeln('Next');
end.

Oh wait…I guess PS does use short circuit evaluation for its and/or operators…
Therefore your code you gave would do exactly what you want it to :).
:duh:, I feel like an idiot lmao.