Inline If Statements: Difference between revisions
From Sierra Wiki
Jump to navigationJump to search
m 1 revision imported |
|||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
''Note: This article only applies to SCI Companion'' | [[Category:SCI Pages]] | ||
[[Category:SCI Pages to be Edited]] | |||
<div align="center"><span style="font-size: 22pt">Inline If Statements</span><br />''By [[Shane Cloud]]''</div> | |||
| |||
<div align="center"><span class="Alert">'''''Note: This article only applies to SCI Companion'''''</div> | |||
<br /> | |||
==<br /> Introduction == | |||
The "if" statement does not return a value, making a the nesting of if's (inline) like this not possible: | The "if" statement does not return a value, making a the nesting of if's (inline) like this not possible: | ||
| Line 12: | Line 21: | ||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
<syntaxhighlight lang="sci" class="cs"> | <syntaxhighlight lang="sci" class="cs"> | ||
(procedure public ( | (procedure public (if pCondition pTrue pFalse) | ||
(if (pCondition) | (if (pCondition) | ||
return pTrue | return pTrue | ||
| Line 34: | Line 43: | ||
==<br /> Also See == | ==<br /> Also See == | ||
* | * | ||
| | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:SCI Examples]] | [[Category:SCI Examples]] | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
[[Category:SCI Scripting]] | |||
[[Category:Syntax]] | [[Category:Syntax]] | ||
[[Category:SCI Syntax]] | |||
[[Category:Conditional Statements]] | |||
Latest revision as of 15:47, 29 April 2025
Note: This article only applies to SCI Companion
Introduction
The "if" statement does not return a value, making a the nesting of if's (inline) like this not possible:
Code:
(if (> a ((if(> b c) 5)(else 9)) d) // This syntax works in SCI Studio, but will not compile in SCI Companion
...
)As indicated above, this code will work in Studio, but will not work in Companion. The way to handle this in Companion is to implement a procedure, which will return a value:
Code:
(procedure public (if pCondition pTrue pFalse)
(if (pCondition)
return pTrue
)(else
return pFalse
)
)The original statement can now be re-written as:
Code:
(if (> a iif(> b c 5 9) d)
...
)
References
Also See