Comment (computer programming): Difference between revisions

Content deleted Content added
By language: Edit fortran for brevity
Examples: Merge Lua into double dash section
Line 471:
</syntaxhighlight>
 
====Double dash====
 
A relatively loose collection of languages use <code>--</code> for a single line comment. Notable languages include: [[Ada (programming language)|Ada]], and[[Eiffel (programming language)|Eiffel]], [[Haskell (programming language)|Haskell]], [[Lua (programming language)|Lua]], [[SQL]] and [[VHDL]]. Block comment support varies. An example in Ada:
 
<syntaxhighlight lang="ada">
Line 523:
\end{code}
Here more explanation using \LaTeX{} markup
</syntaxhighlight>
 
====Block in Lua====
ALua commonsupports techniqueblock tocomments commentdelimited outby a<code>--[[</code> segment ofand <code,>]]</code><ref>{{Cite web|url=http://www.lua.org/pil/1.3.html|title=Programming in Lua 1.3|website=www.Lua.org|access-date=2017-11-08}}</ref> isFor to enclose the code between <code>--[[</code> andexample:
 
<syntaxhighlight lang="lua">
--[[A multi-line
long comment
]]
</syntaxhighlight>
 
Line 635 ⟶ 644:
end program
</syntaxhighlight>
 
====Lua====
[[Lua (programming language)|Lua]] uses double-hyphens, <code>--</code>, for single line comments in a similar way to [[Ada (programming language)|Ada]], [[Eiffel (programming language)|Eiffel]], [[Haskell (programming language)|Haskell]], [[SQL]] and [[VHDL]] languages. Lua also has block comments, which start with <code>--[[</code> and run until a closing <code>]]</code> For example:
 
<syntaxhighlight lang="lua">
--[[A multi-line
long comment
]]
print(20) -- print the result
</syntaxhighlight>
 
A common technique to comment out a segment of code,<ref>{{Cite web|url=http://www.lua.org/pil/1.3.html|title=Programming in Lua 1.3|website=www.Lua.org|access-date=2017-11-08}}</ref> is to enclose the code between <code>--[[</code> and
<code>--]]</code>, as below:
 
<syntaxhighlight lang="lua">
--[[
print(10)
--]]
-- no action (commented out)
</syntaxhighlight>
 
In this case, it's possible to enable the code for use (uncomment-out) by adding a single hyphen to the first line:
 
<syntaxhighlight lang="lua">
---[[
print(10)
--]]
--> 10
</syntaxhighlight>
 
The <code>--[[</code> in the first line starts a long comment, and the two hyphens in the last line
are still inside that comment. In the second example, the sequence <code>---[[</code> starts an ordinary, single-line
comment, so that the first and the last lines become independent comments. In this case, the <code>print</code> is
outside comments. In this case, the last line becomes an independent comment, as it starts with <code>--</code>.
 
====MATLAB====