OpenQASM comments are used to prevent an instructions or instructions from being executed. In this chapter of the OpenQASM Tutorial, you will be learning about OpenQASM comments and using them. The use of comments for preventing execution of a certain part of the code can be for various reasons such as-
- Enhancing the readability of the code by adding human readable logic inside the program file.
- To stop the execution of a certain part of the code for testing or debugging purposes.
OpenQASM 2 supports only single comments.
Single Line Comments
Single line comments start with the double-forward slash- //
and end with the end of that respective line.
Example
Below is an example of a single line comment in OpenQASM 2.0
// An example of a single line comment
Single line comments can also occur after an instruction.
Example
Below is an example of a single line comments that comes after an instruction for initializing a Quantum Register of 4 Qubits.
qreg qubits[4]; //This instruction declares a Quantum Register of 4 Qubits
Single line comments can be used multiple times to create multiple line comments.
Example
Below is an example in which several single line comments are used multiple times.
// This is a single line comment
// multiple single lines comment can be quite painful
// However, multi-line comments do not exist in OpenQASM 2
Commenting multiple lines is the only way to create multiple lines of comments. This is because OpenQASM 2 supports only single line comments.