If function_A returns with True, will function_B be skipped or not?Simba Code:if (function_A or function_B) then
DoSomething;
NextCommand;
If function_A returns with True, will function_B be skipped or not?Simba Code:if (function_A or function_B) then
DoSomething;
NextCommand;
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:
Edit: You should use a more descriptive title next time as I almost skipped itSimba Code: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..
You can do this if you want short circuit evaluation:
Simba Code: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.
Last edited by Sex; 04-04-2012 at 06:53 PM.
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl
"A programmer is just a tool which converts caffeine into code"
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:
Simba Code: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:
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?Code:One ran Expression is true Next
Last edited by Shatterhand; 04-04-2012 at 07:26 PM.
Ah, in that case.
Simba Code: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.
, I feel like an idiot lmao.
Last edited by Sex; 04-04-2012 at 09:33 PM.
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl
"A programmer is just a tool which converts caffeine into code"
There are currently 1 users browsing this thread. (0 members and 1 guests)