code

A comment contains text intended to describe the source which is not executable. The text may be in any language (or none at all). Comments are typically used to either explain obscure code or temporarily remove some code from the program. Comments can be classified by:

Inline comments

Inline comments are generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment.

Examples:

Symbol Languages
C Fortran; the 'C' must be in column 1 of a line to indicate a comment.
REM Basic, COMMAND.COM, cmd.exe
# Perl, Python, Ruby, Windows PowerShell, PHP, Maple
% TeX, Prolog, MATLAB, Erlang, S-Lang
// C, C++, C#, Object Pascal (Delphi), Java, JavaScript, PHP
' Visual Basic, VBScript
! Fortran, Basic Plus
; AutoHotkey, Autoit, Lisp, Scheme, many assemblers
-- Euphoria, Haskell, SQL, ADA, AppleScript, Eiffel, Lua
* Cobol, many assemblers
|| Curl

Block comments

Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context, whitespace and newline characters are not counted as delimiters.

Examples:

Symbol Languages
/* */ AutoHotkey, C, C++, C#, Java, JavaScript, PHP, SQL, Visual Prolog, CSS
""" """ Python, Ruby[1]
''' ''' Python[1]
=begin =cut Perl, Ruby
{- -} Haskell
(* *) Object Pascal (Delphi), ML, Mathematica, Pascal, Applescript, OCaml
{ } Object Pascal (Delphi), Pascal
<!-- --> HTML
|# #| Curl

Unique variants

Fortran

Perl

PHP

Python

Ruby

Curl

Esoteric languages

Comment comparison

There is a wide variety of syntax styles for declaring comments in source code. BlockComment in italics is used here to indicate block comment style. InlineComment in italics is used here to indicate inline comment style.

Smallwikipedialogo.png This page uses content from Wikipedia. The original article was at Comparison of programming languages (syntax)#Comments. The list of authors can be seen in the page history. As with the Programmer's Wiki, the text of Wikipedia is available under the GNU Free Documentation License.
  1. 1.0 1.1 More precisely, the quoted text forms a string literal.