A line comment begins with two forward slashes:
Go code
// Display a greeting
fmt.Println("Hello")Line-by-line explanation
- The first line begins with
//, so it is a comment. - The compiler ignores the comment text.
- The second line displays Hello.
Expected output
HelloThe comment does not appear in the output.
Go also supports block comments beginning with /* and ending with */. Use them sparingly; ordinary line comments are usually easier to edit.
Go code
/* Explain an unusual decision. */
fmt.Println("Ready")Line-by-line explanation
- The first line is a block comment.
- The markers contain the human explanation.
- The second line displays Ready.
Expected output
ReadyOnly the real instruction produces output.