For Statements
A for
statement is made up of:
- optional initializer
- optional condition
- optional continuing
- body
The initializer, condition and continuing are each separated by a ;
.
Example
|
|
Unlike if
and switch
, a for
statement requires parentheses.
Braces are required around the for
body.
All loops in WGSL must terminate.
As with other statement conditions, if provided, the condition must be a boolean expression.
The condition is evaluated before executing the body on each iteration.
If the condition is false
the loop will end.
A break
statement can be used to break out of the closest enclosing
statement.
Example
|
|
|
|
A continue
statement can be used to go to the next iteration
of the enclosing loop.
Example
|
|