Program.if_then

Program.if_then(classical_reg, if_program, else_program=None)[source]

If the classical register at index classical reg is 1, run if_program, else run else_program.

Equivalent to the following construction:

Parameters:
  • classical_reg (Union[MemoryReference, Tuple[str, int], List[Any], str]) – The classical register to check as the condition
  • if_program (Program) – A Quil program to execute if classical_reg is 1
  • else_program (Optional[Program]) – A Quil program to execute if classical_reg is 0. This argument is optional and defaults to an empty Program.
Return type:

Program

Returns:

The Quil Program with the branching instructions added.