Control flow in Silq
Similar to other programming languages, Silq provides control flow statements, which decide the order of execution of the code we write in Silq. Control flow is also known as conditionals, where a condition is provided and executed when some criteria are fulfilled. The statements are executed whenever a certain condition is satisfied.
In the following code, we see an example of a CH gate, which is a two-qubit gate and was discussed in in Chapter 3, Multiple Quantum Bits, Entanglement, and Quantum Circuits. The conditionals are applied using if
and else
statements. Curly brackets, {}
, are used to begin and end a chunk of code. The syntax is given as follows:
if x { // controlled on x, y:=H(y); // apply H to y }
The code shows that if x
qubit is true (meaning it is 1
), then a Hadamard operation will be applied to the y
qubit, which is the controlled Hadamard operation.
Let's look at classical control flow...