This is the ThingsDB documentation for version v0, click here for the latest version!
Runs a block code based on the result of a given condition.
ThingsDB uses lazy-evaluation of function arguments. For this reason if() is a function call, and not a statement like in most other languages.
This function does not generate an event.
if(condition, if_true, [if_false])
Argument | Type | Description |
---|---|---|
condition |
any (required) | The condition to evaluate. |
if_true |
any (required) | Will be executed when the condition evaluated to true . |
if_false |
any (optional) | Will be executed when the condition evaluated to false . |
Returns nil
.
This code shows how if(..) can be used:
if(2 > 1, {
return("two is more than one");
});
"math is broken";
Return value in JSON format
"two is more than one"