# How to implement if statement based on measurement results in qiskit?

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)
qc.measure(q,c)


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

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


into

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:
qc.x(q[0])
qc.x(q[1])


can this work with "c_if"?

• 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? Jan 2, 2020 at 8:21
• 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. Jan 2, 2020 at 11:57

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:
qc.x(q[0]).c_if(c,3)

• 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). Jan 2, 2020 at 12:11