Comments

Published Jul 23, 2021Updated Sep 1, 2023
Contribute to Docs

Comments are text within a program that are not executed by the compiler that 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

Looking to contribute?

Learn Ruby on Codecademy