next up previous contents
Next: Quantum components of the Up: A tutor on the Previous: A tutor on the   Contents

Classical components of the QCL

The Quantum Computing Language contains a number of classical programming components. The term classical refers to non-quantum components. These components are very similar to programming components found in a language like "C". The QCL has 5 data types; int, string complex, boolean real, all of which are fairly self-explanatory. The QCL also implements a full range of logic and arithmetic operators, as well as a large amount of mathematical functions, eg. sin(), cos() etc. The following example shows conditional branching in the QCL;


\begin{lstlisting}[frame=trbl]{}
if e == -1 {
print ''Unable to find a relatively prime number'';
exit;
}
\end{lstlisting}


The QCL provides three types of loops. The for loop is similar to a for loop in C. It also provides two conditional loops, a while loop and an until loop. The following piece of code is an example of a QCL for loop;


\begin{lstlisting}[frame=trbl]{}
complex matrix m[1024];
int i = 0;
for i=0 to 1023 {
m[i,i] = 1;
}
\end{lstlisting}


The QCL also provides a means of grouping statements into blocks and functions. The following is an example of calling a function from another piece of code;
\begin{lstlisting}[frame=trbl]{}
int i = 0;
int n = afunction(i);
...
int afunction(int n) {
....
}
\end{lstlisting}


next up previous contents
Next: Quantum components of the Up: A tutor on the Previous: A tutor on the   Contents
Colm O hEigeartaigh 2003-05-30