Learn how to write comments in Julia’s language.
Comments are useful text to describe lines or functions for developers, ignored by the compiler during the code compilation phase. There are types of comments
- Single-line comments
- Multi-Line comments
- Documentation comments
Julia Single line comments
Single-line comments always start with the #
symbol followed by comment text in a single line.
The compiler ignores the text.
Syntax
\# single line comments
example:
\# hello.jl - prints the text to console
println("Hello World First Program in Julia ")
Nim Multi line comments example
Multi-line comments contain comment text spanned in multiple lines. These are also called block comments.
It always starts with #=
, followed by multiple lines, and ends with =#
.
Here is an example
#=
comment line1 text
comment line2 text
comment line3 text
=#
Output:
#=
hello.jl
print the hello world to the console
simple program to learn julia
=#
println("Hello World First Program in Julia ")
Julia Documentation Comments
Documentation comments are useful for developers about functions, macros, and instance types.
Julia treats any string that comes before functions or any other types as documentation comments. In the below example, Docstring contains a string enclosed in documentation comments.
"Sum function calculates the"
sum(array:: Array)
Another way we can write documentation comments is by passing markdown content, enclosed in """
.
It contains code fences and heading markdown syntaxes.
"""
add(a,b)
the sum of two numbers
\# Examples
```julia
julia> add(1,5)
6
function add(a, b)