23 lines
1.1 KiB
Markdown
23 lines
1.1 KiB
Markdown
## 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:
|
|
|
|
```javascript
|
|
// 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.
|