scf.while
← scf dialect
Unbounded loop with explicit before and after regions. The before region terminates with scf.condition, and the after region terminates with scf.yield.
Operation contract
| Property |
Value |
| Semantic phase |
source structure |
| Interfaces |
LoopLike |
Signature
| Kind |
Name |
Type |
Cardinality |
Description |
| Operand |
iter_args |
any |
variadic |
— |
| Result |
results |
any |
variadic |
— |
| Region |
before |
region |
required |
Runs before each condition check. Terminated by scf.condition. (single block, terminator scf.condition.) |
| Region |
after |
region |
required |
Runs when the condition is true. Terminated by scf.yield. (single block, terminator scf.yield.) |
Verification constraints
IterArgsMatchResults(iter_args, results)
BlockArgCount(before, iter_args)
BlockArgsMatchTypes(before, iter_args)
BlockArgCount(after, iter_args)
BlockArgsMatchTypes(after, iter_args)
YieldCountMatchesResults(after, results)
YieldTypesMatchResults(after, results)
Examples
scf.while {
scf.condition %cond : i1
} do {
scf.yield
}
%result = scf.while(%before = %init : index) -> (index) {
scf.condition %keep_going, %before : i1, index
} do(%body: index) {
%next = index.add %body, %one : index
scf.yield %next : index
}