{{Short description|none}}<!-- This short description is INTENTIONALLY "none" - see WP:SDNONE before considering any change! --> {{Use dmy dates|date=March 2020}} {{ProgLangCompare}}

This article compares the syntax of many notable programming languages.

== Expressions == Programming language expressions can be broadly classified into four syntax structures:

;prefix notation * Lisp <code>(* (+ 2 3) (expt 4 5))</code> ;infix notation * Fortran <code>(2 + 3) * (4 ** 5)</code> ;suffix, postfix, or Reverse Polish notation * Forth <code>2 3 + 4 5 ** *</code> ;math-like notation * TUTOR <code>(2 + 3)(4<sup>5</sup>) $$ note implicit multiply operator</code>

== Statement delimitation == A language that supports the statement construct typically has rules for one or more of the following aspects:

* Statement terminator – marks the end of a statement * Statement separator – demarcates the boundary between two statements; not needed for the last statement * Line continuation – escapes a newline to continue a statement on the next line

Some languages define a special character as a terminator while some, called ''line-oriented'', rely on the newline. Typically, a line-oriented language includes a line continuation feature whereas other languages have no need for line continuation since newline is treated like other whitespace. Some line-oriented languages provide a separator for use between statements on one line.

{| class="wikitable sortable" |- ! Language ! Statement delimitation |- | ABAP<!-- Language --> | period separated |- | Ada<!-- Language --> | semicolon terminated |- | ALGOL<!-- Language --> | semicolon separated |- | ALGOL 68 | semicolon and comma separated<ref>Three different kinds of clauses, each separates phrases and the units differently: *# serial-clause using ''go-on-token'' (viz. semicolon): '''begin''' a; b; c '''end''' – units are executed in order. *# collateral-clause using ''and-also-token'' (viz. ","): '''begin''' a, b, c '''end''' – order of execution is to be optimised by the compiler. *# parallel-clause using ''and-also-token'' (viz. ","): '''par begin''' a, b, c '''end''' – units must be run in parallel threads. </ref> |- | APL | newline terminated, <code>[Direct_function ⋄]</code> separated |- | AppleScript | newline terminated |- | AutoHotkey | newline terminated |- |Awk |newline or semicolon terminated |- | BASIC | newline terminated, colon separated |- | Boo | newline terminated |- | C | semicolon terminated, comma separated expressions |- | C++ | semicolon terminated, comma separated expressions |- | C#<!-- Language --> | semicolon terminated |- | COBOL<!-- Language --> | whitespace separated, sometimes period separated, optionally separated with commas and semi-colons |- | Cobra | newline terminated |- | CoffeeScript | newline terminated |- |Crystal |newline terminated, semicolon separated expressions |- | CSS | semicolon terminated |- | D | semicolon terminated |- | Eiffel | newline terminated, semicolon separated |- | Erlang | colon separated, period terminated |- | F# | newline terminated, semicolon |- | Fortran | newline terminated, semicolon separated |- | Forth | semicolons terminate word definitions; space terminates word use |- | GFA BASIC | newline terminated |- | Go | semicolon separated (inserted by compiler) |- | Haskell | in do-notation: newline separated,<br>in do-notation with braces: semicolon separated |- | Java | semicolon terminated |- | JavaScript | semicolon separated (but often inserted as statement terminator) |- |Kotlin |semicolon separated (but sometimes implicitly inserted on newlines) |- | Lua | whitespace separated (semicolon optional) |- | Mathematica a.k.a. Wolfram | semicolon separated |- | MATLAB | newline terminated, separated by semicolon or comma (semicolon – result of receding statement hidden, comma – result displayed) |- |MUMPS a.k.a. M |newline terminates line-scope, the closest to a "statement" that M has, a space separates/terminates a command, allowing another command to follow |- |Nim |newline terminated |- | Object Pascal (Delphi) | semicolon separated |- | Objective-C | semicolon terminated |- | OCaml | semicolon separated |- | Pascal | semicolon separated |- | Perl | semicolon separated |- | PHP | semicolon terminated |- | Pick Basic | newline terminated, semicolon separated |- | PowerShell | newline terminated, semicolon separated |- | Prolog | comma separated (conjunction), semicolon separated (disjunction), period terminated (clause) |- | Python | newline terminated, semicolon separated |- | R | newline terminated, semicolon separated<ref name="r statement terminators">From the ''R Language Definition'', section 3.2 Control structures: "A semicolon always indicates the end of a statement while a new line may indicate the end of a statement. If the current statement is not syntactically complete new lines are simply ignored by the evaluator."</ref> |- | Raku | semicolon separated |- | Red | whitespace separated |- | Ruby | newline terminated, semicolon separated |- | Rust | semicolon terminated, comma separates expressions |- | Scala | newline terminated, semicolon separator |- | Seed7 | semicolon separated (semicolon termination is allowed) |- | Simula | semicolon separated |- | S-Lang | semicolon separated |- | Smalltalk | period separated |- | Standard ML | semicolon separated |- | Swift | semicolon separated (inserted by compiler) |- |Tcl |newline or semicolon terminated |- | V (Vlang) | newline terminated, comma or semicolon separated |- | Visual Basic | newline terminated, colon separated |- | Visual Basic (.NET) | newline terminated, colon separated |- | Xojo | newline terminated |- | Zig | semicolon terminated |}

=== Line continuation === Listed below are notable line-oriented languages that provide for line continuation. Unless otherwise noted, the continuation marker must be the last text of the line.

;Ampersand * Fortran 90, Fortran 95, Fortran 2003, Fortran 2008

;Backslash * bash<ref>''[https://www.gnu.org/software/bash/manual/bashref.html Bash Reference Manual],'' [https://www.gnu.org/software/bash/manual/bashref.html#Escape-Character 3.1.2.1 Escape Character]</ref> and other Unix shells * C preprocessor macros; used in conjunction with C, C++ and many other programming contexts * Crystal * Mathematica, Wolfram Language * Python<ref>[https://docs.python.org/ Python Documentation], [https://docs.python.org/3/reference/lexical_analysis.html 2. Lexical analysis]: [https://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining 2.1.5. Explicit line joining]</ref> * Ruby * JavaScript – only within single- or double-quoted strings * Vimscript as ''first'' character of continued line

;Backtick * PowerShell

;Hyphen * SQL*Plus

;Underscore * AutoIt * Cobra * Visual Basic * Xojo

;Ellipsis (three dots) * MATLAB: The ellipsis need not end the line, but text following it is ignored.<ref>{{Cite web|url=http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f0-5789.html|archiveurl=https://web.archive.org/web/20100207151905/http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f0-5789.html|url-status=dead|title=Mathworks.com|archivedate=7 February 2010}}</ref> It begins a comment that extends ''through'' (including) the first subsequent newline. Contrast this with a line comment which extends ''until'' the next newline.

;Comma delimiter * Ruby: comment may follow delimiter

;Left bracket delimiter * Batch file: starting a parenthetical block can allow line continuation<ref>{{Cite web|url=https://ss64.com/nt/syntax-brackets.html|title=Parenthesis/Brackets - Windows CMD - SS64.com|website=ss64.com}}</ref> * Ruby: left parenthesis, left square bracket, or left curly bracket

;Operator symbol * Ruby: as last object of line; comment may follow operator * AutoHotkey: As the ''first'' character of continued line; any expression operators except ++ and --, and a comma or a period<ref>{{Cite web |url=https://autohotkey.com/docs/Scripts.htm#continuation |title=Scripts - Definition & Usage &#124; AutoHotkey}}</ref>

;Some form of line comment serves as line continuation * Turbo Assembler: <code>\</code> * m4: <code>dnl</code> * TeX: <code>%</code>

;Character position * Fortran 77: A non-comment line is a continuation of the prior non-comment line if any non-space character appears in column 6. Comment lines cannot be continued. * COBOL: String constants may be continued by not ending the original string in a PICTURE clause with <code>'</code>, then inserting a <code>-</code> in column 7 (same position as the <code>*</code> for comment is used.) * TUTOR: Lines starting with a tab (after any indentation required by the context) continue the prior command.

The C compiler concatenates adjacent string literals even if on separate lines, but this is not line continuation syntax as it works the same regardless of the kind of whitespace between the literals.

== Consuming external software == {{Expand section|date=December 2009}}

Languages support a variety of ways to reference and consume other software in the syntax of the language. In some cases this is importing the exported functionality of a library, package or module but some mechanisms are simpler text file include operations.

Import can be classified by level (module, package, class, procedure,...) and by syntax (directive name, attributes,...).

;File include * <code>#include <''filename''></code> or <code>#include "''filename''"</code> – C preprocessor used in conjunction with C and C++ and other development tools

;File import * <code>addpath(''directory'')</code> – MATLAB<ref>For an M-file (MATLAB source) to be accessible by name, its parent directory must be in the search path (or current directory).</ref> * {{code|COPY filename.|cobolfree}} – COBOL * {{code|import <filename>;|cpp}} or {{code|import "filename";|cpp}} – C++ * <code>:-include("''filename''").</code> – Prolog * <code>#include file="''filename''"</code> – ASP * <code>#include <''filename''></code> or <code>#include "''filename''"</code> – AutoHotkey, AutoIt * <code>#import "''filename''"</code> or <code>#import <''filename''></code> – Objective-C * {{code|Import["filename"]|mathematica}} – Mathematica, Wolfram Language * {{code|include 'filename'|fortran}} – Fortran * <code>include "''filename''";</code> – PHP * <code>include [filename] program</code> or <code>#include [filename] program</code> – Pick Basic * <code>include!("''filename''");</code> – Rust * <code>load "''filename''"</code> – Ruby * {{code|load %filename|red}} – Red * {{ml-lua|filename}} – Lua * <code>require "''filename''";</code> – Perl, PHP * {{code|require "filename"|ruby}} – Ruby, Crystal * {{code|source(""filename"")|r}} – R * <code>@import("''filename''");</code> – Zig

;Package import * <code>#include ''filename''</code> – C * <code>import ''module'';</code> – C++ * <code>#[path = "''filename''"] mod ''altname'';</code> – Rust * <code>@import ''module'';</code> – Objective-C * <code><<''name''</code> – Mathematica, Wolfram Language * {{code|:-use_module(module).|prolog}} – Prolog: * <code>from ''module'' import *</code> – Python * <code>extern crate ''libname'';</code> – or <code>extern crate ''libname'' as ''altname'';</code> or <code>mod ''modname'';</code> – Rust * <code>library("''package''")</code> – R: * <code>IMPORT ''module''</code> – Oberon * <code>import ''altname'' "''package/name''"</code> – Go: * <code>import ''package.module'';</code> or <code>import ''altname'' = ''package.module'';</code> – D * <code>import ''Module''</code> or <code>import qualified ''Module'' as ''M''</code> – Haskell * <code>import ''package''.*</code> – Java, MATLAB, Kotlin * <code>import "''modname''";</code> – JavaScript * <code>import ''altname'' from "''modname''";</code> –JavaScript * <code>import ''package''</code> or <code>import ''package''._</code> – Scala * <code>import ''module''</code> – Swift * <code>import ''module''</code> – V (Vlang) * <code>import ''module''</code> – Python * {{ml-lua|modname}} – Lua * {{Code|require "shard"|ruby}} – Crystal * {{code|require "gem"|ruby}} – Ruby * <code>use ''module''</code> – Fortran 90+ * <code>use ''module'', only : ''identifier''</code> – Fortran 90+ * <code>use ''Module'';</code> – Perl * <code>use Module qw(''import options'');</code> – Perl * <code>use ''Package''.''Name''</code> – Cobra * <code>uses ''unit''</code> – Pascal * <code>with ''package''</code> – Ada * <code>@import("''pkgname''");</code> – Zig

;Class import * <code>from ''module'' import ''Class''</code> – Python * <code>import ''package''.''class''</code> – Java, MATLAB, Kotlin * <code>import ''class'' from "''modname''";</code> – JavaScript * <code>import {''class''} from "''modname''";</code> – JavaScript * <code>import {''class'' as ''altname''} from "''modname''";</code> – JavaScript * <code>import ''package''.''class''</code> – Scala * <code>import ''package''.{ ''class1'' => ''alternativeName'', ''class2'' }</code> – Scala * <code>import ''package''._</code> – Scala * <code>use ''Namespace\ClassName'';</code> – PHP * <code>use ''Namespace\ClassName as AliasName'';</code> – PHP * <code>using ''namespace''::''subnamespace''::''Class'';</code> – C++

;Procedure/function import * <code>from ''module'' import ''function''</code> – Python * <code>import ''package.module'' : ''symbol'';</code> – D * <code>import ''package.module'' : ''altsymbolname'' = ''symbol'';</code> – D * <code>import ''Module'' (''function'')</code> – Haskell * <code>import ''function'' from "modname";</code> – JavaScript * <code>import {''function''} from "''modname''";</code> – JavaScript * <code>import {''function'' as ''altname''} from "''modname''";</code> – JavaScript * <code>import ''package''.''function''</code> – MATLAB * <code>import ''package''.''class''.''function''</code> – Scala * <code>import ''package''.''class''.{ ''function'' => ''alternativeName'', ''otherFunction'' }</code> – Scala * {{code|use Module ('symbol');|perl}} – Perl * <code>use function ''Namespace\function_name'';</code> – PHP * <code>use ''Namespace\function_name as function_alias_name'';</code> – PHP * <code>using ''namespace''::''subnamespace''::''symbol'';</code> – C++ * <code>use ''module''::''submodule''::''symbol'';</code> – Rust * <code>use ''module''::''submodule''::{''symbol1'', ''symbol2''};</code> – Rust * <code>use ''module''::''submodule''::''symbol'' as ''altname'';</code> – Rust

;Constant import * <code>use const ''Namespace\CONST_NAME'';</code> – PHP

The above statements can also be classified by whether they are a syntactic convenience (allowing things to be referred to by a shorter name, but they can still be referred to by some fully qualified name without import), or whether they are actually required to access the code (without which it is impossible to access the code, even with fully qualified names).

;Syntactic convenience * <code>import ''package''.*</code> Java * <code>import ''package''.''class''</code> Java * <code>open ''module''</code> OCaml * <code>using namespace ''namespace''::''subnamespace'';</code> – C++ * <code>use ''module''::''submodule''::*;</code> – Rust

;Required to access code * <code>import ''module'';</code>C++ * <code>import altname "''package/name''"</code> Go * <code>import ''altname'' from "''modname''";</code>JavaScript * <code>import ''module''</code>Python

== Block delimitation == A '''block''' is a grouping of code that is treated collectively. Many block syntaxes can consist of any number of items (statements, expressions or other units of code), including one or zero. Languages delimit a block in a variety of ways: some via marking text and others by relative formatting such as levels of indenting.

;Curly braces (a.k.a. curly brackets) <code>{</code> ... <code>}</code>: * Curly brace languages: A defining aspect of curly brace languages is that they use curly braces to delimit a block.<!--too many to list-->

;Parentheses <code>(</code> ... <code>)</code> * Batchfile, F# (lightweight syntax),<ref name = "fsharp">{{cite web |url = https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/verbose-syntax |title = Verbose Syntax - F# <nowiki>|</nowiki> Microsoft Learn |date = 2021-11-05 |access-date = 17 November 2022 |website = Microsoft Learn}}</ref> OCaml, Prolog, Standard ML ;Square brackets <code>[</code> ... <code>]</code> * Rebol, Red, Self, Smalltalk (blocks are first class objects. a.k.a. closures) ;<code>begin</code> ... <code>end</code>: * Ada, ALGOL, F# (verbose syntax),<ref name = "fsharp"/> Pascal, Ruby (<code>for</code>, <code>do/while</code> & <code>do/until</code> loops), Crystal, OCaml, SCL, Simula, Erlang. ;<code>do</code> ... <code>end</code>: * PL/I, REXX ;<code>do</code> ... <code>done</code>: * Bash (<code>for</code> & <code>while</code> loops), F# (verbose syntax)<ref name = "fsharp"/> Visual Basic, Fortran, TUTOR (with mandatory indenting of block body), Visual Prolog ;<code>do</code> ... <code>end</code> * Lua, Ruby (pass blocks as arguments, <code>for</code> loop), Seed7 (encloses loop bodies between '''<code>do</code>''' and '''<code>end</code>''') ;X ... <code>end</code>''' (e.g. <code>if</code> ... <code>end</code>):''' * Ruby (<code>if</code>, <code>while</code>, <code>until</code>, <code>def</code>, <code>class</code>, <code>module</code> statements), OCaml (<code>for</code> & <code>while</code> loops), MATLAB (<code>if</code> & <code>switch</code> conditionals, <code>for</code> & <code>while</code> loops, <code>try</code> clause, <code>package</code>, <code>classdef</code>, <code>properties</code>, <code>methods</code>, <code>events</code>, & <code>function</code> blocks), Lua (<code>then</code> / <code>else</code> & <code>function</code>) ;(<code>begin</code> ...): * Scheme ;(progn ...): * Lisp ;(<code>do</code> ...): * Clojure

;Indentation * Off-side rule languages: Boo, Cobra, CoffeeScript, F#, Haskell (in do-notation when braces are omitted), LiveScript, occam, Python, Nemerle (Optional; the user may use white-space sensitive syntax instead of the curly-brace syntax if they so desire), Nim, Scala (Optional, as in Nemerle) * Free-form languages: most descendants from ALGOL (including C, Pascal, and Perl); Lisp languages

;Others * Ada, Visual Basic, Seed7: <code>if</code> ... <code>end if</code> * ALGOL 68: <code>begin</code> ... <code>end</code>, <code>(</code> ... <code>)</code>, <code>if</code> ... <code>fi</code>, <code>do</code> ... <code>od</code> * APL: <code>:If</code> ... <code>:EndIf</code> or <code>:If</code> ... <code>:End</code> * Bash, sh, and ksh: <code>if</code> ... <code>fi</code>, <code>do</code> ... <code>done</code>, <code>case</code> ... <code>esac</code>; * COBOL: <code>IF</code> ... <code>END-IF</code>, <code>PERFORM</code> ... <code>END-PERFORM</code>, etc. for statements; ... <code>.</code> for sentences.* Lua, Pascal, Modula-2, Seed7: <code>repeat</code> ... <code>until</code> * Small Basic: <code>If</code> ... <code>EndIf</code>, <code>For</code> ... <code>EndFor</code>, <code>While</code> ... <code>EndWhile</code> * Visual Basic (.NET): <code>If</code> ... <code>End If</code>, <code>For</code> ... <code>Next</code>, <code>Do</code> ... <code>Loop</code>

== Comments == With respect to a language definition, the syntax of Comments can be classified many ways, including: * Line vs. block – a line comment starts with a delimiter and continues to the end of the line (newline marker) whereas a block comment starts with one delimiter and ends with another and can cross lines * Nestable – whether a block comment can be inside another block comment * How parsed with respect to the language; tools (including compilers and interpreters) may also parse comments but that may be outside the language definition

Other ways to categorize comments that are outside a language definition:

* Inline vs. prologue – an inline comment follows code on the same line and a prologue comment precedes program code to which it pertains; line or block comments can be used as either inline or prologue * Support for API documentation generation which is outside a language definition

=== Line comment ===

{| class="wikitable" |- ! Symbol ! Languages |- |<code>C</code> |Fortran I to Fortran 77 (C in column 1) |- |<code>REM</code> |BASIC, Batch files, Visual Basic |- |<code>::</code> |Batch files, COMMAND.COM, cmd.exe |- |- |<code>NB.</code> |J; from the (historically) common abbreviation Nota bene, the Latin for "note well". |- |- |<code>⍝</code> |APL; the mnemonic is that the glyph (jot overstruck with shoe-down) resembles a desk lamp, and hence "illuminates" the foregoing. |- |<code>#</code> |Boo, Bourne shell and other UNIX shells, Cobra, Crystal, Perl, Python, Ruby, Seed7, PowerShell, PHP, R, Make, Maple, Elixir, Julia, Nim<ref>{{Cite web|url=https://nim-lang.org/docs/manual.html#lexical-analysis-comments|title=Nim Manual|website=nim-lang.org}}</ref> |- |<code>%</code> |TeX, Prolog, MATLAB,<ref name=Mathworks.com>{{cite web|title=Mathworks.com|url=http://www.mathworks.de/de/help/matlab/matlab_prog/comments.html|access-date=25 June 2013|archive-url=https://web.archive.org/web/20131121055151/http://www.mathworks.de/de/help/matlab/matlab_prog/comments.html|archive-date=21 November 2013|url-status=dead}}</ref> Erlang, S-Lang, Visual Prolog, PostScript |- |<code>//</code> |ActionScript, Boo, C (C99), C++, C#, D, F#, Go, Java, JavaScript, Kotlin, Object Pascal (Delphi), Objective-C, PHP, Rust, Scala, Sass, Swift, Xojo, V (Vlang), Zig |- |<code>'</code> |Monkey, Visual Basic, VBScript, Small Basic, Gambas, Xojo |- |<code>!</code> |Factor, Fortran, Basic Plus, Inform, Pick Basic |- |<code>;</code> |Most assembly languages, AutoHotkey, AutoIt, Lisp, Common Lisp, Clojure, PGN, Rebol, Red, Scheme |- |<code><nowiki>--</nowiki></code> |Euphoria, Haskell, SQL, Ada, AppleScript, Eiffel, Lua, VHDL, SGML, PureScript, Elm |- |<code>*</code> |Assembler S/360 (* in column 1), COBOL I to COBOL 85, PAW, Fortran IV to Fortran 77 (* in column 1), Pick Basic, GAMS (* in column 1) |- |<code><nowiki>||</nowiki></code> |Curl |- |<code><nowiki>"</nowiki></code> |Vimscript, ABAP |- |<code><nowiki>\</nowiki></code> |Forth |- |<code>*></code> |COBOL 90 |}

=== Block comment === In these examples, <code>~</code> represents the comment content, and the text around it are the delimiters. Whitespace (including newline) is not considered delimiters.

{| class="wikitable" |- ! Syntax ! Languages |- | <code>comment</code> ~ <code>;</code> | ALGOL 60, Simula |- | <code>¢</code> ~ <code>¢</code>,<br/><code>#</code> ~ <code>#</code>, <code>co</code> ~ <code>co</code>,<br/><code>comment</code> ~ <code>comment</code> | ALGOL 68<ref name=algolcomments>{{cite web|title=Algol68_revised_report-AB.pdf on PDF pp. 61–62, original document pp. 121–122|url=http://www.softwarepreservation.org/projects/ALGOL/report/Algol68_revised_report-AB.pdf|access-date=27 May 2014}}</ref><ref name=algolcomments2>{{cite web|title=HTML Version of the Algol68 Revised Report AB|url=http://jmvdveer.home.xs4all.nl/report.html#941h|access-date=27 May 2014|url-status=dead|archiveurl=https://web.archive.org/web/20130317015548/http://jmvdveer.home.xs4all.nl/report.html#941h|archivedate=17 March 2013}}</ref> |- | <code>/*</code> ~ <code>*/</code> | ActionScript, AutoHotkey, C, C++, C#, CSS, D,<ref name=dcomments>{{cite web|title=DLang.org, Lexical|url=http://dlang.org/lex.html#comment|access-date=27 May 2014}}</ref> Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/I, Prolog, Rexx, Rust (can be nested), Scala (can be nested), SAS, SASS, SQL, Swift (can be nested), V (Vlang), Visual Prolog |- | <code>#cs</code> ~ <code>#ce</code> | AutoIt<ref name=autoitscriptcomments>{{cite web|title=AutoItScript.com Keyword Reference, #comments-start|url=https://www.autoitscript.com/autoit3/docs/keywords/comments-start.htm|access-date=27 May 2014}}</ref> |- | <code>/+</code> ~ <code>+/</code> | D (can be nested)<ref name=dcomments/> |- | <code>/#</code> ~ <code>#/</code> | Cobra (can be nested) |- | <code>&lt;#</code> ~ <code>#&gt;</code> | PowerShell |- | <code>&lt;!--</code> ~ <code>--&gt;</code> | HTML, XML |- | <code>=begin</code> ~ <code>=cut</code> | Perl (Plain Old Documentation) |- | <code>#`(</code> ~ <code>)</code> | Raku (bracketing characters can be (), <>, {}, [], any Unicode characters with BiDi mirrorings, or Unicode characters with Ps/Pe/Pi/Pf properties) |- | <code>=begin</code> ~ <code>=end</code> | Ruby |- | <code>#<TAG></code> ~ <code>#</TAG></code>, {{nowrap|<code>#stop</code> ~ <code>EOF</code>,}}<br/><code>#iffalse</code> ~ <code>#endif</code>, {{nowrap|<code>#ifntrue</code> ~ <code>#endif</code>,}}<br/><code>#if false</code> ~ <code>#endif</code>, {{nowrap|<code>#if !true</code> ~ <code>#endif</code>}} | S-Lang<ref>{{cite web|title=slang-2.2.4/src/slprepr.c – line 43 to 113|url=ftp://space.mit.edu/pub/davis/slang/v2.2/slang-2.2.4.tar.bz2|archive-url=https://web.archive.org/web/20171121010846/ftp://space.mit.edu/pub/davis/slang/v2.2/slang-2.2.4.tar.bz2|archive-date=2017-11-21|url-status=dead|access-date=28 May 2014}}</ref> |- | <code>{-</code> ~ <code>-}</code> | Haskell (can be nested), Elm |- | <code>(*</code> ~ <code>*)</code> | Delphi, ML, Mathematica, Object Pascal, Pascal, Seed7, AppleScript, OCaml (can be nested), Standard ML (can be nested), Maple, Newspeak, F# |- | <code>{</code> ~ <code>}</code> | Delphi, Object Pascal, Pascal, PGN, Red |- | <code>{#</code> ~ <code>#}</code> | Nunjucks, Twig |- | <code>{{!</code> ~ <code>}}</code> | Mustache, Handlebars |- | <code>{{!--</code> ~ <code>--}}</code> | Handlebars (cannot be nested, but may contain <code>{{</code> and <code>}}</code>) |- | <code><nowiki>|#</nowiki></code> ~ <code><nowiki>#|</nowiki></code> | Curl |- | <code>%{</code> ~ <code>%}</code> | MATLAB<ref name="Mathworks.com"/> (the symbols must be in a separate line) |- | <code><nowiki>#|</nowiki></code> ~ <code><nowiki>|#</nowiki></code> | Lisp, Scheme, Racket (can be nested in all three). |- | <code><nowiki>#=</nowiki></code> ~ <code><nowiki>=#</nowiki></code> | Julia<ref>{{cite web|url=https://docs.julialang.org/en/v1/base/punctuation/ | title=Punctuation · The Julia Language}}</ref> |- | <code><nowiki>#[</nowiki></code> ~ <code><nowiki>]#</nowiki></code> | Nim<ref>{{Cite web|url=https://nim-lang.org/docs/manual.html#lexical-analysis-multiline-comments|title=Nim Manual|website=nim-lang.org}}</ref> |- | <code>--<nowiki></nowiki></code> ~ <code></code>,<br/><code>--[=[</code> ~ <code>]=]</code>,<br/><code>--[==[</code> ~ <code>]==]</code> etc. | Lua (brackets can have any number of matching <code>=</code> characters; can be nested within non-matching delimiters) |- | <code>"</code> ~ <code>"</code> | Smalltalk |- | <code>(comment</code> ~ <code>)</code> | Clojure |- | <code>#If COMMENT Then</code> ~ {{nowrap|<code>#End If</code>}}{{efn|Visual Basic (.NET) does not support traditional multi-line comments, but they can be emulated through compiler directives.}} | Visual Basic (.NET) |- | <code>#if COMMENT</code> ~ <code>#endif</code>{{efn|name=cs-cd|While C# supports traditional block comments <code>/* ... */</code>, compiler directives can be used to mimic them, as in VB.NET.}} | C# |- | <code>' comment _</code>,<br/>{{nowrap|<code>REM comment _</code>}}{{efn|name=vb|The line continuation character <code>_</code> can be used to extend a single-line comment to the next line without needing to type <code>'</code> or <code>REM</code> again. This can be done up to 24 times in a row.}} | Classic Visual Basic, VBA, VBScript |}

=== Unique variants ===

;Fortran Indenting lines in Fortran 66/77 is significant. The actual statement is in columns 7 through 72 of a line. Any non-space character in column 6 indicates that this line is a continuation of the prior line. A '<code>C</code>' in column 1 indicates that this entire line is a comment. Columns 1 though 5 may contain a number which serves as a label. Columns 73 though 80 are ignored and may be used for comments; in the days of punched cards, these columns often contained a sequence number so that the deck of cards could be sorted into the correct order if someone accidentally dropped the cards. Fortran 90 removed the need for the indenting rule and added line comments, using the <code>!</code> character as the comment delimiter.

;COBOL In fixed format code, line indenting is significant. Columns 1–6 and columns from 73 onwards are ignored. If a <code>*</code> or <code>/</code> is in column 7, then that line is a comment. Until COBOL 2002, if a <code>D</code> or <code>d</code> was in column 7, it would define a "debugging line" which would be ignored unless the compiler was instructed to compile it.

;Cobra Cobra supports block comments with "<code>/#</code> ... <code>#/</code>" which is like the "<code>/*</code> ... <code>*/</code>" often found in C-based languages, but with two differences. The <code>#</code> character is reused from the single-line comment form "<code>#</code> ...", and the block comments can be nested which is convenient for commenting out large blocks of code.

;Curl Curl supports block comments with user-defined tags as in <code>|foo# ... #foo|</code>.

;Lua Like raw strings, there can be any number of equals signs between the square brackets, provided both the opening and closing tags have a matching number of equals signs; this allows nesting as long as nested block comments/raw strings use a different number of equals signs than their enclosing comment: <code>--[[comment --[=[ nested comment ]=] ]]</code>. Lua discards the first newline (if present) that directly follows the opening tag.

;Perl Block comments in Perl are considered part of the documentation, and are given the name Plain Old Documentation (POD). Technically, Perl does not have a convention for including block comments in source code, but POD is routinely used as a workaround.

;PHP PHP supports standard C/C++ style comments, but supports Perl style as well.

;Python The use of the triple-quotes to comment-out lines of source, does not actually form a comment.<ref>[https://twitter.com/gvanrossum/status/112670605505077248 "Python tip: You can use multi-line strings as multi-line comments"], 11 September 2011, Guido van Rossum</ref> The enclosed text becomes a string literal, which Python usually ignores (except when it is the first statement in the body of a module, class or function; see docstring).

;Elixir The above trick used in Python also works in Elixir, but the compiler will throw a warning if it spots this. To suppress the warning, one would need to prepend the sigil <code>~S</code> (which prevents string interpolation) to the triple-quoted string, leading to the final construct <code>~S""" ... """</code>. In addition, Elixir supports a limited form of block comments as an official language feature, but as in Perl, this construct is entirely intended to write documentation. Unlike in Perl, it cannot be used as a workaround, being limited to certain parts of the code and throwing errors or even suppressing functions if used elsewhere.<ref>{{cite web |url = https://hexdocs.pm/elixir/1.12.3/writing-documentation.html |title = Writing Documentation — Elixir v1.12.3 |access-date = 2023-07-28}}</ref>

;Raku Raku uses <code>#`(...)</code> to denote block comments.<ref>{{cite web|url=https://docs.perl6.org/language/syntax#Comments |title=Perl 6 Documentation (Syntax) |at=Comments |publisher=docs.perl6.org |access-date=2017-04-05}}</ref> Raku actually allows the use of any "right" and "left" paired brackets after <code>#`</code> (i.e. <code>#`(...)</code>, <code>#`[...]</code>, <code>#`{...}</code>, <code>#`<...></code>, and even the more complicated <code>#`&#123;{...}&#125;</code> are all valid block comments). Brackets are also allowed to be nested inside comments (i.e. <code>#`{ a { b } c }</code> goes to the last closing brace).

;Ruby Block comment in Ruby opens at <code>=begin</code> line and closes at <code>=end</code> line.

;S-Lang The region of lines enclosed by the <code><nowiki>#&lt;tag&gt;</nowiki></code> and <code><nowiki>#&lt;/tag&gt;</nowiki></code> delimiters are ignored by the interpreter. The tag name can be any sequence of alphanumeric characters that may be used to indicate how the enclosed block is to be deciphered. For example, <code><nowiki>#&lt;latex&gt;</nowiki></code> could indicate the start of a block of LaTeX formatted documentation.

;Scheme and Racket The next complete syntactic component (s-expression) can be commented out with <code>#;</code> .

;ABAP ABAP supports two different kinds of comments. If the first character of a line, including indentation, is an asterisk (<code>*</code>) the whole line is considered as a comment, while a single double quote (<code>"</code>) begins an in-line comment which acts until the end of the line. ABAP comments are not possible between the statements <code>EXEC SQL</code> and <code>ENDEXEC</code> because Native SQL has other usages for these characters. In the most SQL dialects the double dash (<code>--</code>) can be used instead.

;Esoteric languages Many esoteric programming languages follow the convention that any text not executed by the instruction pointer (e.g., Befunge) or otherwise assigned a meaning (e.g., Brainfuck), is considered a "comment".

=== Comment comparison === There is a wide variety of syntax styles for declaring comments in source code. <code>''BlockComment''</code> in italics is used here to indicate block comment style. <code>''LineComment''</code> in italics is used here to indicate line comment style.

{| class="wikitable" |- ! Language ! In-line comment ! Block comment |- |Ada, Eiffel, Euphoria, Occam, SPARK, ANSI SQL, and VHDL |<code>-- ''LineComment''</code> | |- |ALGOL 60 | |<code>comment ''BlockComment'';</code> |- |ALGOL 68 | |<code>¢ ''BlockComment'' ¢</code><br/> <code><u>comment</u> ''BlockComment'' <u>comment</u></code><br/> <code><u>co</u> ''BlockComment'' <u>co</u></code><br/> <code># ''BlockComment'' #</code><br/> <code>£ ''BlockComment'' £</code><br/> |- |APL |<code>⍝ ''LineComment''</code> | |- |AppleScript |<code>-- ''LineComment''</code> |<code>(* ''BlockComment'' *)</code> |- |Assembly language (varies) |<code>; ''LineComment''</code>&nbsp;&nbsp; one example (most assembly languages use line comments only) | |- |AutoHotkey |<code>; ''LineComment''</code> |<code>/* ''BlockComment'' */</code> |- |AWK, Bourne shell, C shell, Maple, PowerShell |<code># ''LineComment''</code> |<code><# ''BlockComment'' #></code> |- |Bash |<code># ''LineComment''</code> |<code><nowiki><<EOF</nowiki><br/>''BlockComment''<br/>EOF</code><br/><br/><code>: '<br/>''BlockComment''<br/>'</code> |- |BASIC (various dialects): |<code><nowiki>'</nowiki>''LineComment''</code> (not all dialects)<br/> <code>*''LineComment''</code> (not all dialects)<br/> <code>!''LineComment''</code> (not all dialects)<br/> <code>REM ''LineComment''</code> | |- |C (K&R, ANSI/C89/C90), CHILL, PL/I, REXX | |<code>/* ''BlockComment'' */</code> |- |C (C99), C++, Go, Swift, JavaScript, V (Vlang) |<code>// ''LineComment''</code> |<code>/* ''BlockComment'' */</code> |- |C# |<code>// ''LineComment''</code><br/><code>/// ''LineComment''</code> (XML documentation comment) |<code>/* ''BlockComment'' */</code><br/><code>/** ''BlockComment'' */</code> (XML documentation comment)<br/><code>#if COMMENT<br/>&nbsp; ''BlockComment''<br/>#endif</code> (Compiler directive){{efn|name=cs-cd}} |- |COBOL I to COBOL 85 |<code> * ''LineComment''</code> (* in column 7) | |- |COBOL 2002 |<code>*> ''LineComment''</code> | |- |Curl |<code>&#124;&#124; ''LineComment''</code> |<code>&#124;# ''BlockComment'' #&#124;</code><br/> <code>&#124;foo# ''BlockComment'' #&#124;</code> |- |Cobra |<code># ''LineComment''</code> |<code>/# ''BlockComment'' #/</code> (nestable) |- |D |<code>// ''LineComment''</code><br/><code>/// Documentation ''LineComment''</code> (ddoc comments) |<code>/* ''BlockComment'' */</code><br/><code>/** Documentation ''BlockComment'' */</code> (ddoc comments)<br/> <code>/+ ''BlockComment'' +/</code> (nestable)<br/><code>/++ Documentation ''BlockComment'' +/</code> (nestable, ddoc comments) |- |DCL |<code>$! ''LineComment''</code> | |- |ECMAScript (JavaScript, ActionScript, etc.) |<code>// ''LineComment''</code> |<code>/* ''BlockComment'' */</code> |- |Elixir |<code># ''LineComment''</code> |<code>~S"""<br/>''BlockComment''<br/>"""</code><br/><code>@doc """<br/>''BlockComment''<br/>"""</code> (Documentation, only works in modules)<br/><code>@moduledoc<br/>''BlockComment''<br/>"""</code> (Module documentation)<br/><code>@typedoc<br/>''BlockComment''<br/>"""</code> (Type documentation) |- |Forth |<code>\ ''LineComment''</code> |<code>( ''BlockComment'' )</code> (single line and multiline)<br/> <code>( ''before'' -- ''after'' )</code> stack comment convention |- |FORTRAN I to FORTRAN 77 |<code>C ''LineComment''</code> (C in column 1) | |- |Fortran 90 and later |<code>! ''LineComment''</code> |<code>#if 0<br/>&nbsp; ''BlockComment''<br/>#endif</code>{{efn|Fortran does not support traditional block comments, but some compilers support preprocessor directives in the style of C/C++, allowing a programmer to emulate multi-line comments.<ref>{{cite web |url = https://www.cism.ucl.ac.be/Services/Formations/ICS/ics_2013.0.028/composerxe/Documentation/en_US/compiler_f/main_for/GUID-4A598AC5-1C5F-48F2-BA42-DA8F38D46CB3.htm |title = Using the FPP Preprocessor |archive-url = https://web.archive.org/web/20221118125512/https://www.cism.ucl.ac.be/Services/Formations/ICS/ics_2013.0.028/composerxe/Documentation/en_US/compiler_f/main_for/GUID-4A598AC5-1C5F-48F2-BA42-DA8F38D46CB3.htm |access-date = 18 November 2022|archive-date = 18 November 2022 }}</ref>}} |- |Haskell |<code>-- ''LineComment''</code> |<code>{- ''BlockComment'' -}</code> |- |J |<code>NB.</code> | |- |Java |<code>// ''LineComment''</code> |<code>/* ''BlockComment'' */</code><br/> <code>/** ''BlockComment'' */</code> (Javadoc documentation comment) |- |Julia |<code># ''LineComment'' </code> |<code><nowiki>#=</nowiki> ''BlockComment'' <nowiki>=#</nowiki></code> |- |Lisp, Scheme |<code>; ''LineComment''</code> |<code>#&#124; ''BlockComment'' &#124;#</code> |- |Lua |<code>-- ''LineComment''</code> |<code><nowiki> --[==[ </nowiki>''BlockComment''<nowiki>]==]</nowiki></code> (variable number of = signs, nestable with delimiters with different numbers of = signs) |- |Maple |<code># ''LineComment''</code> |<code>(* ''BlockComment'' *)</code> |- |Mathematica | |<code>(* ''BlockComment'' *)</code> |- |MATLAB |<code>% ''LineComment''</code> |<code>%{<br/>''BlockComment (nestable)''<br/>%}</code>{{efn|Both percent–bracket symbols must be the only non-whitespace characters on their respective lines.}} |- |Nim |<code># ''LineComment'' </code> |<code><nowiki>#[</nowiki> ''BlockComment'' <nowiki>]#</nowiki></code> |- |Object Pascal |<code>// ''LineComment''</code> |<code>(* ''BlockComment'' *)</code><br/><code>{ ''BlockComment'' }</code> |- |OCaml | |<code>(* ''BlockComment (* nestable *)'' *)</code> |- |Pascal, Modula-2, Modula-3, Oberon, ML: | |<code>(* ''BlockComment'' *)</code> |- |Perl, Ruby |<code># ''LineComment'' </code> |<code>=begin<br/>''BlockComment''<br/>=cut</code> (<code>=end</code> in Ruby) (POD documentation comment)<br/> <code><nowiki>__END__</nowiki><br/>''Comments after end of code''</code> |- |PGN, Red |<code>; ''LineComment''</code> |<code>{ ''BlockComment'' }</code> |- |PHP |<code># ''LineComment''</code><br/><code>// ''LineComment''</code> |<code>/* ''BlockComment'' */</code><br/><code>/** Documentation ''BlockComment'' */</code> (PHP Doc comments) |- |PILOT |<code>R:''LineComment''</code> | |- |PLZ/SYS | |<code>! ''BlockComment'' !</code> |- |PL/SQL, TSQL |<code>-- ''LineComment''</code> |<code>/* ''BlockComment'' */</code> |- |Prolog |<code>% ''LineComment''</code> |<code>/* ''BlockComment'' */</code> |- |Python |<code># ''LineComment'' </code> |<code><nowiki>'''</nowiki> ''BlockComment'' <nowiki>'''</nowiki><br/>""" ''BlockComment'' """</code><br/> (Documentation string when first line of module, class, method, or function) |- |R |<code># ''LineComment''</code> | |- |Raku |<code># ''LineComment'' </code> |<code>#`{<br/>''BlockComment''<br/>}</code><br/> <code>=comment<br/>''&nbsp;&nbsp;&nbsp;&nbsp;This comment paragraph goes until the next POD directive''<br/>''&nbsp;&nbsp;&nbsp;&nbsp;or the first blank line.''</code><ref>{{cite web |url=https://docs.perl6.org/language/pod#Pod_comments |title=Perl 6 POD Comments|date=25 May 2023 }}</ref><ref>{{cite web |url=https://docs.perl6.org/language/pod#Abbreviated_blocks |title=Perl 6 POD (Abbreviated Blocks)|date=25 May 2023 }}</ref> |- |Rust |<code>// ''LineComment''</code><br/> <code>/// ''LineComment''</code> ("Outer" rustdoc comment)<br/> <code>//! ''LineComment''</code> ("Inner" rustdoc comment) |<code>/* ''BlockComment'' */</code> (nestable)<br/> <code>/** ''BlockComment'' */</code> ("Outer" rustdoc comment)<br/> <code>/*! ''BlockComment'' */</code> ("Inner" rustdoc comment) |- |SAS | |<code>* ''BlockComment'';</code><br/><code>/* ''BlockComment'' */</code> |- |Seed7 |<code># ''LineComment''</code> |<code>(* ''BlockComment'' *)</code> |- |Simula | |<code>comment ''BlockComment'';</code><br/><code>! ''BlockComment'';</code> |- |Smalltalk | |<code>"''BlockComment''"</code> |- |Smarty | |<code>{* ''BlockComment'' *}</code> |- |Standard ML | |<code>(* ''BlockComment'' *)</code> |- |TeX, LaTeX, PostScript, Erlang, S-Lang |<code>% ''LineComment''</code> | |- |Texinfo |<code>@c ''LineComment''</code> <code>@comment ''LineComment''</code> | |- |TUTOR |<code>* ''LineComment''</code><br/><code>''command'' $$ ''LineComment''</code> | |- |Visual Basic |<code><nowiki>'</nowiki> ''LineComment''</code><br/><code>Rem ''LineComment''</code> |<code><nowiki>'</nowiki> ''BlockComment'' _<br/>''BlockComment''</code><br/><code>Rem ''BlockComment'' _<br/>''BlockComment''</code>{{efn|name=vb}} |- |Visual Basic (.NET) |<code><nowiki>'</nowiki> ''LineComment''</code><br/> <code><nowiki>'''</nowiki> ''LineComment''</code> (XML documentation comment)<br/> <code>Rem ''LineComment''</code> | <code>#If COMMENT Then<br/>&nbsp; ''BlockComment''<br/>#End If</code> |- |Visual Prolog |<code>% ''LineComment''</code> |<code>/* ''BlockComment'' */</code> |- |Wolfram Language | |<code>(* ''BlockComment'' *)</code> |- |Xojo |<code>' ''LineComment''</code><br/><code>// ''LineComment''</code><br/><code>rem ''LineComment''</code> |- |Zig |<code>// ''LineComment''</code><br/><code>/// ''LineComment''</code><br/><code>//! ''LineComment''</code> | |}

== See also == * C syntax * C++ syntax * List of programming languages by type#curly-brace, a broad family of programming language syntaxes * Java syntax * JavaScript syntax * PHP syntax and semantics * Python syntax and semantics

== References == {{Reflist}}

== Notes == {{Notelist}}

*Syntax <!-- Hidden categories below --> Category:Articles with example Ada code Category:Articles with example ALGOL 60 code Category:Articles with example ALGOL 68 code Category:Articles with example BASIC code Category:Articles with example C code Category:Articles with example C++ code Category:Articles with example C Sharp code Category:Articles with example Fortran code Category:Articles with example Haskell code Category:Articles with example Java code Category:Articles with example JavaScript code Category:Articles with example Julia code Category:Articles with example Lisp (programming language) code Category:Articles with example MATLAB/Octave code Category:Articles with example OCaml code Category:Articles with example Pascal code Category:Articles with example Perl code Category:Articles with example PHP code Category:Articles with example Python (programming language) code Category:Articles with example Racket code Category:Articles with example Rust code Category:Articles with example Scala code Category:Articles with example Smalltalk code Category:Articles with example Swift code