Tour of WGSL

If Statements

For simple branching, the if statement is provided for control flow.

An if statement requires a condition, which must be a boolean.

The parenthesis are optional around the condition, the braces are required around the body.

Example
if a {
} else if (b) {
}

An if can be followed by zero or more else if blocks and a single optional else block.

Example
if a {
} else if b {
} else if c {
} else {
}

The else must come last.