If
이 페이지에서

If()

함수, 작성 분류

Author if (cond) { body } over the innermost active scope.

import { If } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

const If: (
cond: ReadonlyNode<"bool">,
body: () => ReadonlyNode | void,
) => IfChain

매개변수

cond ReadonlyNode<'bool'>

the branch condition.

body () => ReadonlyNode | void

the statements of the branch, authored through the ambient functions.

반환값

IfChain

the chain, for .elif and .else.

예외

SD0115

SD0115 when the body returns a value.

설명

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.

예제

예제

If(d.lt(0.001), () => {
Break()
}).else(() => {
t.assign(t.add(d))
})

관련 가이드

함께 보기

소스

src/core/ir/builder.ts, 1805행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고