ReturnIf
On this page

ReturnIf()

Function in Authoring

Guard clause: if (cond) { return value; }, the explicit early return that reads as "return value if cond".

import { ReturnIf } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

const ReturnIf: (cond: ReadonlyNode<"bool">, value?: ReadonlyNode) => void

Parameters

cond ReadonlyNode<'bool'>

the guard condition.

valueoptional ReadonlyNode

the value to return; omit it for a bare return;.

Return value

void

Description

Guard clause: if (cond) { return value; }, the explicit early return that reads as “return value if cond”. It emits the same statements as If(cond, () => Return(value)). A native return inside an If body emits nothing, so an early return from a branch is written in one of these two forms.

Examples

Example

ReturnIf(winding.ne(0), f32(1).sub(min_dist))
Return(f32(1).add(min_dist))

In the guide

Source

src/core/ir/builder.ts, line 1721, at commit 26de7be8

Edit this page Report a problem