if
The if
statement is used to conditionally execute one or more statements. In conjunction with an optional else
statement it can cause one or other of two blocks of statements to be executed depending on whether an expression is true or false.
Syntax
if
(expression)
{
# Statements
} [else {
# Statements
}]
Details
If the condition evaluates to true, then the first block of statements is executed, and the second block (if present) is skipped over. If the condition evaluates to false then the first block of statements is skipped and the second block (if present) is executed.
The opening {
character at the start of each block may be placed on a line of its own if preferred but the closing }
must be on a line of its own.
Multiple conditions can be used in a single expression and combined with the boolean operators &&
or ||
(for AND and OR respectively) so long as each condition is enclosed in braces. For example:
Example
Given the source JSON in a file called example.json
, the following USE script:
will produce the following output:
Last updated
Was this helpful?