I tried to implement three qubit bit flip code in qiskit and need to get the result of measurements and then apply recovery quantum operations conditioned on the measurement results. The following is a simplified version to initialize a circuit:

q= QuantumRegister(3)
c= ClassicalRegister(3)
qc= QuantumCircuit(q, c)

I noticed that this question had a similar question and they transformed the statement

if(c[0]==0) qc.x(q[0])


qc.x(q[0]).c_if(c[0], 0)

However, I want to have multiple quantum operations conditioned on the if statement

if c[0]==1 and c[1]==1:

can this work with "c_if"?

  • $\begingroup$ I wonder what these if's physically mean. IMO quantum computer consists of qubits, gates that can be applied to qubits, and measurements; there is no external logic to branch a program on a measurement outcome. You can branch a program on a measurement outcome using controlled gates such as CNOT and additional qubit(s); is this how if's are implemented? $\endgroup$
    – kludg
    Jan 2, 2020 at 8:21
  • $\begingroup$ I agreed. The "c_if" statement seems like a programming language and to implement it physically need controlled gates. I think qiskit provides this logic for simplicity. $\endgroup$
    – Jacey Li
    Jan 2, 2020 at 11:57

1 Answer 1


AFAIK, what you want can't be run on the hardware right now. See this github issue.

However, you can do this in the simulators. If, for example, c[0] and c[1] make up a two-bit classical register c, you can do this:

  • $\begingroup$ Thank you. Does "c_if(c,3)" mean that both two bits in classical register are equal to 3? Can bits in classical register equal differently, such as "if(c[0]==0 and c[1]==1)"? $\endgroup$
    – Jacey Li
    Jan 2, 2020 at 11:35
  • 6
    $\begingroup$ The value of the classical register c is interpreted as a number in binary. Thus, c_if(c,3) means c[0]==1 and c[1]==1. If you want c[0]==0 and c[1]==1, the condition is c_if(c,2). $\endgroup$ Jan 2, 2020 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.