You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: SPEC.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -7146,11 +7146,11 @@ Example output:
7146
7146
7147
7147
### Conditional Statement
7148
7148
7149
-
A conditional statement consists of the `if` keyword, followed by a `Boolean` expression and a body of (potentially nested) statements. The conditional body is only evaluated if the conditional expression evaluates to `true`.
7149
+
A conditional statement consists of one or more conditional clauses. Each conditional clause is comprised of an expression that evaluates to a `Boolean`and an associated clause body. When a conditional statement is executed, each of the conditional clauses is evaluated sequentially: (a) the expression for that clause is evaluated and, if the returned value is `true`, the body of that clause is executed and the entire conditional statement suspends further execution. The simplest conditional statement contains a single "if" clause, which is the `if` keyword, followed by the clause's boolean expression, and, finally, the clause body of (potentially nested) statements wrapped in curly brackets.
7150
7150
7151
7151
After evaluation of the conditional has completed, each declaration or call output in the conditional body is exposed in the enclosing context as an optional declaration. In other words, for a declaration or call output `T <name>` within a conditional body, a declaration `T? <name>` is implicitly available outside of the conditional body. If the expression evaluated to `true`, and thus the body of the conditional was evaluated, then the value of each exposed declaration is the same as its original value inside the conditional body. If the expression evaluated to `false` and thus the body of the conditional was not evaluated, then the value of each exposed declaration is `None`.
7152
7152
7153
-
The scoping rules for conditionals are similar to those for scatters - declarations or call outputs inside a conditional body are accessible within that conditional and any nested statements.
7153
+
The scoping rules for conditionals are similar to those for scatters—declarations or call outputs inside a conditional body are accessible within that conditional and any nested statements.
7154
7154
7155
7155
In the example below, `Int j` is accessible anywhere in the conditional body, and `Int? j` is an optional that is accessible outside of the conditional anywhere in `workflow test_conditional`.
7156
7156
@@ -7231,7 +7231,9 @@ Example output:
7231
7231
</p>
7232
7232
</details>
7233
7233
7234
-
WDL has no `else` keyword. To mimic an `if-else` statement, you would simply use two conditionals with inverted boolean expressions. A common idiom is to use `select_first` to select a value from either the `if` or the `if not` body, whichever one is defined.
7234
+
After the initial `if` clause, conditional statements may have any number of `else if` clauses and a single, final `else` clause. As described in the paragraph above, `else if` clauses are only evaluated if all prior clauses in the statement have evaluated to `false`. If present, the final `else` clause executes only if all prior clauses evaluated to `false`.
7235
+
7236
+
When gathering results from conditionals, a common idiom is to use `select_first` to select a value from one of the `if`, `else if`, or `else` bodies—whichever one is defined.
7235
7237
7236
7238
<details>
7237
7239
<summary>
@@ -7246,7 +7248,7 @@ task greet {
7246
7248
}
7247
7249
7248
7250
command <<<
7249
-
printf "Good ~{time} buddy!"
7251
+
printf "Good ~{time} buddy!"
7250
7252
>>>
7251
7253
7252
7254
output {
@@ -7259,13 +7261,11 @@ workflow if_else {
7259
7261
Boolean is_morning = false
7260
7262
}
7261
7263
7262
-
# the body *is not* evaluated since 'b' is false
7263
7264
if (is_morning) {
7265
+
# The body *is not* evaluated since `is_morning` is `false`.
7264
7266
call greet as morning { time = "morning" }
7265
-
}
7266
-
7267
-
# the body *is* evaluated since !b is true
7268
-
if (!is_morning) {
7267
+
} else {
7268
+
# The body *is* evaluated since the clause above did not trigger.
0 commit comments