How do i Comment in various Programming Languages?

How do i Comment in various Programming Languages

Comment is all about the text which you want to write your own descriptions of the code that compiler ignore. It is always added to make the code understandable. The Syntax and rules for comments vary language to language.

Comments are generally formatted as block comments (also called prologue comments or stream comments) or line comments (also called inline comments).

Block comments delimit a region of source code in which the region is allowed to span multiple lines. This region is specified with a start delimiter and an end delimiter. Some programming languages (such as MATLAB) allow block comments to be recursively nested inside one another, but others (such as Java) do not.

Line comments either start with a comment delimiter and continue until the end of the line, or in some cases, start at a specific column (character line offset) in the source code, and continue until the end of the line.

Some programming languages employ both block and line comments with different comment delimiters. For example, C++ has block comments delimited by /* and */ that can span multiple lines and line comments delimited by //. Other languages support only one type of comment. For example, Ada comments are line comments: they start with — and continue to the end of the line.

These are the following programming languages with comments type:

1. C

// this line will be ignored by the compiler /* these lines   will be ignored   by the compiler */ x = *p/*q;  /* note: this comment starts after the ‘p’ */

2. C++

/* This is a single line comment */
// This is a single one line comment
/*   This is a multiple line comment*/

3. C#

///<summary>

///summary description

///</summary>
/* This is a multi-line comment   and continues until the end   of comment symbol is reached */

4. Java

/**

* Registers the text to display in a tool tip.   The text

* displays when the cursor lingers over the component.

*

* @param text  the string to display.  If the text is null,

*              the tool tip is turned off for this component.

*/

public void setToolTipText(String text) {

5. VB

‘ Requirements:

‘ Requires advapi.dll and Windows 98/NT+

‘ ********************* Comments
In VB There is no multiline commentapostrophe is the only comment marker in vb. net

6. HTML

<!–This is a comment. Comments are not displayed in the browser–>

7. XML

The syntax for writing comments in XML is similar to that of HTML.
<!– This is a comment –>

8. ASP

<%

‘Hello I am a comment

Dim newVar1, newVar2

‘Dim oldVar1, oldVar2

%>

9. PHP

In PHP, we use // to make a one-line comment or /* and */ to make a comment block:

10. Unix Shell Scripts

Comment lines in unix Shell script start with a hash character.# commentmycommand myparameters

# comment
There is no multiline comment option in shell scripting
Alternatively we can use this
: <<‘END’

comments’ here

and here

END
Reference: http://www.unix.com/shell-programming-scripting/39478-block-comment-shell-script.html

11. Oracle

With /*…*/, as in C.

With a line that begins with two dashes –.
Thus:

— This is a comment

SELECT * /* and so is this */

12. SQL

Comments in SQL are in single-line-only form, when using two dashes:

— This is a single line comment

— followed by a second line

SELECT COUNT(*)        FROM Authors       WHERE Authors.name = ‘Smith’; — Note: we only want ‘smith’                                     — this comment appears after SQL code
The syntax for Transact-SQL also supports alternative formats for specifying comments. One format supported by this syntax is identical to the “block comment” style used in the syntax for C++ and Java.

/*This is a comment line 1This is a comment line 2*/

SELECT COUNT(*)       FROM Authors

13. F#

//singleline commment
(* This is a comment *)

(* Sample hello world program *)

printfn “Hello World!”

14. Matlab

Comment lines begin with the character ‘%’, and anything after a ‘%’ character is ignored by the interpreter. The % character itself only tells the interpreter to ignore the remainder of the same line.
% Calculate average velocity, assuming acceleration is constant% and a frictionless environment.

15. Cold Fusion

<!— This prints “Hello World” to the browser. —>

<cfoutput>   Hello World<br /> </cfoutput>

16. Fortran IV

C

C Lines that begin with ‘C’ (in the first or ‘comment’ column) are comments

C

WRITE (6,10)    10 FORMAT(12H HELLO WORLD)       END

17. Fortran 90

!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

!*All characters after an exclamation mark are considered as comments *

!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

PRINT “WIKIPEDIA” ! Fortran 90 introduced the option for inline comments.

END

18. Objective CAML

codeLine(* comment level 1(*comment level 2*)*)

19. Perl

#!/usr/bin/perl

my $s = “Wikipedia”; # Sets the variable s to “Wikipedia”.

print $s . “\n”;     # Add a newline character after printing for shells that do not do so automatically.

20. Python

#!/usr/bin/env python

# this program prints “Hello World” to the screen and then quits.

print “Hello World!”
def foo(x, y):

”’Frobnicate the bar and baz

together with one another”’

return frob(frob(x), frob(y))

21. Ruby

Single line commenting: (line starts with hash “#”)

puts “This is not a comment”

#this is commented

puts “This is not a comment”
Multi-line commenting: (comments goes between keywords “begin” and “end”)

puts “This is not a comment”

=begin

whatever goes in here

will be ignored 🙂

=end

puts “This is not a comment”

22. Haskell

Single line comments in Haskell start with ‘–‘ (two dashes), and multiple line comments start with ‘{-‘ and end with ‘-}’.

{- this is a comment

on more lines -}

— and this is a comment on one line

putStrLn “Wikipedia”

23. Basic Classic

In FORTRAN, BASIC, and COBOL languages, comments are full lines; and each comment is begun by a specific comment mark in a fixed position on the line. In BASIC,  REMark lines start with REM.
010 REM    FIND PRIME NUMBERS LESS THAN 100

020 REM    BY DENNIE VAN TASSEL

030 REM    JULY 4, 1965

040 LET A = 1

24.COBOL

COBOL has a similar style of comments. An asterisk has to be put in position 7, and then the rest of the line is a comment. COBOL labels have to start in position 8 or later, and COBOL statements have to start in position 12 or later. Here are how comments would look in COBOL:

010010*   FIND PRIME NUMBERS LESS THAN 100

010020*   BY DENNIE VAN TASSEL

010030*   JULY 4, 1959

010035 START-LOOP.

010040       MOVE 1 TO A.

25. Assembly Language

End of line comment

;  (semicolon)

26. MYSQL

MySQL Server supports three comment styles:
From a “#” character to the end of the line.
From a “– ” sequence to the end of the line. This style is supported as of MySQL 3.23.3. In MySQL, the “– ” (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on). This syntax differs slightly from standard SQL comment syntax, as discussed in Section 1.9.5.8, “’–‘ as the Start of a Comment”.
From a /* sequence to the following */ sequence, as in the C programming language. This syntax enables a comment to extend over multiple lines because the beginning and closing sequences need not be on the same line.

Thanks for your Attentions

* Comment in various Programming Languages

R K Gupta

Hi, This is R K Gupta, an IT professional and Entrepreneur. I have written many articles yet for my websites gsesoftsolutions.com, Hope you like it. Kindly subscribe our feed for any updates. Add me in Facebook and Google+

More Posts - Website

Follow Me:
TwitterFacebookPinterestYouTube

Hi, This is R K Gupta, an IT professional and Entrepreneur. I have written many articles yet for my websites gsesoftsolutions.com, Hope you like it. Kindly subscribe our feed for any updates. Add me in Facebook and Google+

Posted in Software Development