Comments in Julia

Comments are the statements in a code that are ignored by the compiler at the time of execution. These statements are written to beautify the code, providing an explanation for the steps that are used in the code. During coding, proper use of comments makes maintenance easier and finding bugs easily.
 
In Julia, comments are used in a similar manner as in Python. Comments can be of two types, based on their usage. These are:

  • Single Lined comments
  • Multi lined comments

Comments are generally used for the following purposes:

  • Code Readability
  • Explanation of the code or Metadata of the project
  • Prevent execution of code
  • To include resources

Single Line Comments

Single line comments in Julia start with the hashtag symbol(#) and lasts till the end of the line. If the comment exceeds one line then put a hashtag on the next line and continue the comment. Julia’s single lined comments are useful for supplying short explanations for function declarations, variables, and expressions. See the following code snippet demonstrating single line comment:
Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# This is a comment  
# Print "GeeksforGeeks !" to console  
print("GeeksforGeeks")  

chevron_right


Output:
Comments-Output-01

In the above code, the compiler ignores the statement written after #, because it considers the line as a comment and skips its execution.



Multi-Line Comments

Julia multi-line comment is a piece of text enclosed in a delimiter (#=) on start of the comment and (=#) on the end of the comment. A multiline comment is useful when the comment text does not fit into one line; therefore needs to span across lines. Multi-line comments or paragraphs serve as documentation for others reading your code. See the following code snippet demonstrating multi-line comment:

filter_none

edit
close

play_arrow

link
brightness_4
code

#= This would be a multiline comment in Julia that  
spans several lines and describes geeksforgeeks.  
A Computer Science portal for geeks. It contains   
well written, well thought   
and well-explained computer science   
and programming articles,   
quizzes and more.
=# print("GeeksForGeeks")

chevron_right


Output:
Comments-Output-02

In the above code snippet, the statements that are inclosed within #= and =# are considered as comments and are ignored by the compiler at the time of Code execution.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.