Comments
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
.
=beginI 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 valuescount = 0for i in 1..10 doif (i % 2 == 0)count += iendendputs count# Yields a total of 30
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Ruby on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn Ruby
Learn to program in Ruby, a flexible and beginner-friendly language used to create sites like Codecademy.Beginner Friendly9 hours