If()
Function in Authoring
Author if (cond) { body } over the innermost active scope.
import { If } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
const If: ( cond: ReadonlyNode<"bool">, body: () => ReadonlyNode | void,) => IfChainParameters
condReadonlyNode<'bool'>the branch condition.
body() => ReadonlyNode | voidthe statements of the branch, authored through the ambient functions.
Return value
the chain, for .elif and .else.
Exceptions
Description
Chain .elif(c, () => …) and
.else(() => …) on the returned IfChain. A native return inside the body
callback only exits that closure; for an early return from the branch write
Return or ReturnIf.
Because that value goes nowhere, a body that returns one is rejected with SD0115 instead
of being accepted as an empty branch: If(c, () => f32(1)) differs from
If(c, () => Return(f32(1))) by three characters and by everything else. For a value,
reach for when.
Examples
Example
If(d.lt(0.001), () => { Break()}).else(() => { t.assign(t.add(d))})In the guide
See also
Source
src/core/ir/builder.ts, line 1805, at commit 26de7be8