Do you forget how to comment your code, or even worse forget to comment at all? Below you’ll find comment syntax for some of the top programming and scripting languages.
Python
Comments in Python are single-line only. Start the comment with #
print("Hello, World!") #This is a comment #print("Hello, World!") #This is a #Multi-line #Comment
C++
Comments in C++ are written with //
for single-line and /* */
for multi-line.
cout << "Hello World!"; // This is a comment /* this is a multi-line comment */ cout << "Hello World!";
C
Comments in C are written with //
for single-line and /* */
for multi-line.
// Single-line comment #include <stdio.h> int main(void) { // This is a single line comment /* Multi-line comment */ }
C#
Comments in C# are written with //
for single-line and /* */
for multi-line.
Console.WriteLine("Hello World!"); // This is a comment /* Multi-line comment */
Java
Comments in Java are written with //
for single-line and /* */
for multi-line.
// Single Line Comment System.out.println("Hello World"); /* Multi-line comment */
Perl
Comments in Perl are written with #
for single-line and =begin
=end
for multi-line comments.
# single line comment =begin begin and end must be on their own line =end
Ruby
Comments in Ruby are written with #
for single-line and =begin
=end
for multi-line comments.
# single line comment =begin begin and end must be on their own line =end
HTML
Comments in HTML are the same whether they are multi or single-line. Put your comment between <!--
and -->
<!-- This is a single-line comment -->; <!-- This is a multi-line comment -->
CSS
Comments in CSS are the same whether they are multi or single-line. Put your comment between /*
and */
a{ /* This is a single-line comment */ /* text-align: center; */ /* This is a multi-line comment */ /* color: #ffffff; font-size: 150%; */ }
JavaScript
Comments in JavaScript can be made by adding an //
before a single-line comment or putting the comment between /*
and */
for a multi-line comment
// single line comment var a = 2; //sets var a to 2 /* single line comment */ var a = 2; /* sets var a to 2 */ /* multi line comment */ /* var a is set to 2 below */ var a = 2;
PHP
Comments in PHP can be made by adding an #
or //
before a single-line comment or putting the comment between /*
and */
for a multi-line comment
<?php // This is a single-line comment # This is also a single-line comment /* This is a multi-line comment */ ?>
SQL
Comments in SQL can be made either single line using --
(or using #
in MYSQL) at the beginning of the line or surrounding the comment in /* */
SELECT 1+1; -- This comment continues to the end of line SELECT 1 /* this is an in-line comment */ + 1; SELECT 1+ /* this is a multiple-line comment */ 1;