Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > SDL script for generating code > Keywords > if...then...else statement (SDL script)
  
if...then...else statement (SDL script)
An if...then...else statement provides a mechanism for conditional execution of statements in SDL script.
If...then...else statements can be nested.
An if...then...else statement uses the following keywords:
%if - starts the if...then...else statement and specifies the condition to be evaluated. For information about working with variables, item properties, item lists and operators, see the following topics:
Keywords for working with item lists (SDL script)
Keywords for working with items properties (SDL script)
Keywords for working with variables (SDL script)
Overview of operators (SDL script)
%then - specifies a set of statements to run if the condition is satisfied.
%else - optional keyword that specifies a set of statements to run if the condition is not satisfied.
%endif - ends the if...then...else statement.
Syntax
%if <condition> %then
<set of statements for when condition is satisfied>
[%else
<set of statements for when condition is not satisfied>]
%endif
In this example the value of the Return Type property is evaluated. If the value of the Return Type property is void, 'return;' is generated, if the value is not void, 'return ReturnValue;' is generated.
%if %custom "Return Type" == "void" %then
"return;"
%else
"return ReturnValue;"
%endif