Switch Statements
Similar to if statements, a switch statement can be used to branch
over multiple blocks.
A switch has a condition, the condition must be a concrete integer
scalar type. The case
selectors must have the same type as the condition.
Like with if, the parentheses around the condition are
optional.
A switch can have zero or more case blocks.
A default block is required. Multiple default blocks are not
permitted
case and default blocks require braces.
There is no fallthrough in WGSL, but cases can have multiple
selectors. default may be included in the multi-selector list.
Example
let a = 4;
switch a {
case 1, 2, 3: {
}
default: {
}
}
// Default can be included in the selector list
switch a {
case 1, 2, default: {
}
}