mimiqcircuits.operations.whilestatement¶
Conditional loop (WhileStatement).
Classes
|
Conditional loop operation. |
- class mimiqcircuits.operations.whilestatement.WhileStatement(operation, bitstring)[source]¶
Bases:
OperationConditional loop operation.
Repeatedly applies the provided operation while the classical register matches the specified
BitString.WhileStatementis the loop counterpart ofIfStatement. The body operationopis executed once for every iteration in which the classical register’s state equals theBitString. For the loop to terminate,opmust mutate at least one of the bits used in the condition;WhileStatementallows body bits to alias condition bits, which is the only way to make progress.There is no built-in iteration cap — a non-terminating circuit is the user’s responsibility, mirroring how every classical language treats
while.Examples
>>> from mimiqcircuits import * >>> c = Circuit() >>> c.push(WhileStatement(Not(), BitString('1')), 0, 0) 1-bit circuit with 1 instruction: └── WHILE(c==1) ! @ c[0], condition[0]
See also
IfStatement
- property op¶
- property bitstring¶