Comments

Anonymous contributor's avatar
Anonymous contributor
Published Jul 23, 2021Updated Jul 10, 2024
Contribute to Docs

Comments are text within a program that are not executed by the compiler or interpreter. They may aid in describing what is happening in the code.

Single-line Comments

Single-line comments start with a #.

# I am a single line comment.

Multi-line Comments

Multi-line comments start with =begin and end with =end.

=begin
I am a multi line comment.
I can take as many lines as needed.
=end

Example

The example below shows how single-line comments can be used in code.

# This example uses a loop to sum only the even values
count = 0
for i in 1..10 do
if (i % 2 == 0)
count += i
end
end
puts count
# Yields a total of 30

All contributors

Contribute to Docs

Learn Ruby on Codecademy