while Statement

Executes a statement block until the conditional expression fails.

[Attribute] while ( Conditional ) { Statement Block; }



An optional parameter that controls how the statement is compiled.

Attribute Description
unroll(x) Unroll the loop until it stops executing. Optionally, you can specify the maximum number of times the loop can execute.
loop Use flow-control statements in the compiled shader; do not unroll the loop.
fastopt Reduces the compile time but produces less aggressive optimizations. If you use this attribute, the compiler will not unroll loops.
This attribute affects only shader model targets that support break instructions. This attribute is available in shader model vs_2_x and shader model 3 and later. It is particularly useful in shader model 4 and later when the compiler compiles loops. The compiler simulates loops by default to evaluate whether it can unroll them. If you do not want the compiler to unroll loops, use this attribute to reduce compile time.
allow_uav_condition Allows a compute shader loop termination condition to be based off of a UAV read. The loop must not contain synchronization intrinsics.


A conditional expression. If the expression evaluates to true, the statement block is executed. The loop ends when the expression evaluates to false.

Statement Block

One or more statements.

See also

Flow Control