Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A block comment (also known as a general comment) in Go is a lexical construct that instructs the compiler to ignore a specific sequence of characters. It begins with the character sequence /* and terminates with the first subsequent occurrence of */.
/*
This is a block comment.
The Go compiler ignores all text
between the opening and closing markers.
*/

Lexical Characteristics

Token Parsing During lexical analysis, the Go scanner evaluates block comments as whitespace. The exact interpretation depends on the contents of the comment:
  • If the block comment contains one or more newline characters (\n), the scanner treats the entire comment as a single newline. This is critical for Go’s automatic semicolon insertion rules.
  • If the block comment contains no newlines, the scanner treats it as a single space character.
Inline Placement Because block comments have an explicit termination sequence, they can be placed inline between other valid lexical tokens without commenting out the remainder of the line.
func calculateTotal(base int, multiplier int) int {
    return base /* base value */ * multiplier
}
Non-Nesting Rule Go block comments do not nest. The lexical scanner terminates the comment at the very first */ sequence it encounters, regardless of how many opening /* sequences preceded it. Attempting to nest block comments will expose the trailing text to the compiler, resulting in a syntax error.
/*
    Level 1 Comment
    /*
        Level 2 Comment
    */ 
    The compiler attempts to parse this text because the comment 
    was terminated by the `*/` above. This causes a compilation error.
*/
Master Go with Deep Grasping Methodology!Learn More