assistance-engine/ingestion/docs/11_Conditional_statements.txt

41 lines
2.3 KiB
Plaintext

IF-THEN-ELSE Statement
The IF-THEN-ELSE statement in AVAP™ allows for decision-making based on specific conditions and executes different blocks of code depending on the outcome of those conditions. Below is a detailed explanation of its syntax and functionality.
6.1 Syntax of the IF-THEN-ELSE Statement
The basic syntax of the IF-THEN-ELSE statement in AVAP™ is as follows:
if(condition, true_value, operator)
// Block of code if the condition is true else()
// Block of code if the condition is false end()
condition: This is an expression that evaluates to either true or false.
true_value: This is the value assigned if the condition is true.
operator: This is the operator used to compare the condition with the true value.
6.2 Functioning of the IF-THEN-ELSE Statement
The IF-THEN-ELSE statement evaluates the given condition and, if it is true, executes the block of code within the IF(). If the condition is false, it executes the block of code within the ELSE().
Below is the description of each part of the IF-THEN-ELSE statement using the provided example:
// IF, ELSE and END Sample Use
addVar(selector,'yes')
if(selector,'yes','=')
addVar(result,1)
else()
addVar(result,0)
end()
addResult(result)
The variable selector is initialized with the value 'yes'.
The statement IF(selector,'yes','=') evaluates whether the value of selector is equal to 'yes'. In this case, the condition is true.
Inside the IF() block, addVar(result,1) is executed, which assigns the value 1 to the result variable.
Since the condition of the IF() is true, the code block inside the ELSE() is not executed.
The statement addResult(result) adds the value of the result variable to the API result.
6.3 Result
The result returned by the API after executing the above code is as follows:
{
status
, elapsed:0.008270740509033203, result: { result:1 }
}
This result indicates that the execution was successful (status:true) and that the value of result is 1.
6.4 Conclusions
The IF-THEN-ELSE statement in AVAP™ provides an efficient way to make decisions based on specific conditions. Similar to other programming languages, it allows for executing different blocks of code based on the outcome of evaluating a condition.