<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">etrusco wrote</div>
<div class="quote-message">
On Feb 2, 2016 7:41 PM, "geneb" <<a href="/user/SendEmail.jtp?type=node&node=5723966&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>> wrote:
<br>
[...]
<br>
The problem with Iff() is:
1) it either retains normal function behavior and thus has to evaluate both expressions (i.e. suboptimal performance and allowing side effects);
</div>
</div></blockquote>
<br>
Well:
<pre>
program Project1;
function test1: integer;
begin
WriteLn('A');
Result := 10;
end;
function test2: integer;
begin
WriteLn('B');
Result := 20;
end;
function CommonFunc(A: Boolean; B, C: integer): integer;
begin
if A then
Result := B
else
Result := C;
end;
var
X: LongInt;
begin
X := IfThen(True, test1, test2);
WriteLn(X);
WriteLn('----');
X := CommonFunc(True, test1, test2);
WriteLn(X);
ReadLn;
end.
</pre>
Result:
<pre>
A
10
----
B
A
10
</pre>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://free-pascal-general.1045716.n5.nabble.com/Re-if-then-else-expression-tp5723834p5723966.html">Re: if-then-else expression</a><br/>
Sent from the <a href="http://free-pascal-general.1045716.n5.nabble.com/">Free Pascal - General mailing list archive</a> at Nabble.com.<br/>